1
using
System;
2 using System.Drawing;
3 using System.ComponentModel;
4 using System.Windows.Forms;
5
6 namespace my_control
7 {
8 //所有控件必须派生自Control类
9 public class CustomControl : System.Windows.Forms.Control
10 {
11 //重载控件的OnPaint方法
12 protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
13 {
14 //绘制字符串
15 e.Graphics.DrawString("Written with GDI+ on OnPaint event",
16 new Font("Arial",12), new SolidBrush(Color.Red), 0, 0);
17 }
18 }
19}
2 using System.Drawing;
3 using System.ComponentModel;
4 using System.Windows.Forms;
5
6 namespace my_control
7 {
8 //所有控件必须派生自Control类
9 public class CustomControl : System.Windows.Forms.Control
10 {
11 //重载控件的OnPaint方法
12 protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
13 {
14 //绘制字符串
15 e.Graphics.DrawString("Written with GDI+ on OnPaint event",
16 new Font("Arial",12), new SolidBrush(Color.Red), 0, 0);
17 }
18 }
19}
完整控件代码和控件测试程序下载:my_control.rar