用VS建两个项目(CustomControlSample, TestControl), 项目类型分别是类库(不是内裤!!!), Windows应用程序.
1
using System.Windows.Forms;
2
using System.Drawing;
3
4
namespace 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
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

只有一个属性的控件!!!
拖到windows 窗体上:

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

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