最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
[原创]IssueVision 学习笔记(二)-----为控件添加自定义属性和事件-Web_Serv
时间:2022-07-02 11:17:27 编辑:袖梨 来源:一聚教程网
我们先来看看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.")]
再看一下在另一个用户控件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.")]
相关文章
- 网站优化如何提高用户的信任度? 07-12
- 比特币Coinbase溢价回升,但强度仍低于6月峰值——这对BTC意味着什么? 07-12
- 无畏契约源能行动霓虹实战 霓虹实战技巧详解 07-12
- 幻兽帕鲁流沙蛇去哪捕捉 帕鲁流沙蛇抓取方法介绍 07-12
- Web3遊戲《Seraph》代幣閃崩60%!官方緊急宣布回購$SERAPH 07-12
- 幻兽帕鲁滑水蛇怎么获得 帕鲁滑水蛇获取方法 07-12