Dot Net WinForm 控件开发 (一) 写一个最简单的控件

      用VS建两个项目(CustomControlSample, TestControl), 项目类型分别是类库(不是内裤!!!), Windows应用程序.

 1using System.Windows.Forms;
 2using System.Drawing;
 3
 4namespace CustomControlSample
 5{
 6    public class FirstControl : Control
 7    {
 8        private int simpleField;
 9
10        public int SimpleProperty
11        {
12            get return simpleField; }
13            set { simpleField = value; }
14        }

15
16        protected override void OnPaint(PaintEventArgs e)
17        {
18            base.OnPaint(e);
19            e.Graphics.DrawRectangle(Pens.Red, new Rectangle(Point.Empty, new Size(Width - 1, Height - 1)));
20        }

21    }

22}

只有一个属性的控件!!!

拖到windows 窗体上:


在属性浏览器中可以看到该控件的唯一属性:


一个最最简单的Dot net winform控件做好了.
The end.

原文地址:https://www.cnblogs.com/luqingfei/p/674518.html