因为已经有人写过关于自定义控件的基本资料,我在这儿就不写了,只提一些重点。
自定义控件可以继承Control、UserControl和.NET 提供的标准类库(Window From)。
现在我们就来写本系列的第一个控件JLabel控件,它继承自Cotrol,基本和.NET提供的Label控件相似,但是没有Label控件强大。本控件只起指导作用,用户可自行修改。
代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
namespace JFormControl
{
public class JLabel:Control
{
public JLabel():base()
{
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
}
#region 文本对齐方式
private ContentAlignment cAlign=ContentAlignment.MiddleCenter;
/// <summ