第三章例题:自定义控件

对教材p120部分创建控件进行演示
 1using System;
 2using System.Drawing;
 3using System.ComponentModel;
 4using System.Windows.Forms;
 5
 6namespace 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), 00);
17        }

18    }

19}

 完整控件代码和控件测试程序下载:my_control.rar

posted @ 2007-03-31 09:57  dn  阅读(181)  评论(0编辑  收藏  举报