一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

[原创]IssueVision 学习笔记(二)-----为控件添加自定义属性和事件-Web_Serv

时间:2008-01-12 编辑:简简单单 来源:一聚教程网

我们先来看看IssueVision中一个用户控件PaneCaption在可视化设计器中的属性窗口.
再看一下在另一个用户控件StaffPane中使用它时的属性窗口:
大家会发现它多出来很多个属性,这些属性是原来继承控件中没有的属性,如:InactiveTextColor,InactiveTextColor等等.它们是如何实现的呢?我们就来看一下这个用户控件的代码PaneCaption.cs吧.
namespace IssueVision
{
// Custom control that draws the caption for each pane. Contains an active
// state and draws the caption different for each state. Caption is drawn
// with a gradient fill and antialias font.
public class PaneCaption : UserControl
{
private class Consts
{
......
可以看到它是由 System.Windows.Forms.UserControl 继承而来,图一显示了它的默认属性.下面我们接着PaneCaption.cs代码,看看是如何将属性或事件显示在可视化设计器中.
[DefaultValueAttribute(typeof(Color), "3, 55, 145")]
[DescriptionAttribute("Low color of the inactive gradient.")]
[CategoryAttribute("Appearance")]
public Color InactiveGradientLowColor
{
get
{
return m_colorInactiveLow;
}
set
{
if (value == Color.Empty)
{
value = Color.FromArgb(3, 55, 145);
}
m_colorInactiveLow = value;
CreateGradientBrushes(); //自定义方法,用于创建线形渐变笔刷
Invalidate(); //Control.Invalidate 方法,使控件的特定区域无效并向控件发送绘制消息
}
}
[CategoryAttribute("Appearance")]
[DescriptionAttribute("High color of the inactive gradient.")]

热门栏目