Welcome

首页 / 软件开发 / .NET编程技术 / WinForm控件开发总结(三) 认识WinForm控件常用的Attribute

WinForm控件开发总结(三) 认识WinForm控件常用的Attribute2011-11-14 博客园 纶巾客在前面的文章里我们制作了一个非常简单的控件。现在我们回过头来看看这些代码透露出什么信息。

这个类是直接从Control类派生出来的,自定义控件都是直接从Control类派生出来的。这个类定义了 一个属性TextAlignment,用来控制文本在控件中显示的位置:

         [        Category("Alignment"),        Description("Specifies the alignment of text.")        ]        public ContentAlignment TextAlignment        {            get            {                return alignmentValue;            }            set            {                alignmentValue = value;                // The Invalidate method invokes the OnPaint method described                 // in step 3.                Invalidate();            }        }