public class Button:ButtonBase
{
private string caption;
public string Caption {
get {
return caption;
}
set {
caption = value;
Repaint();
}
}
}
在vs.net下实例化你的类button 然后运行就自动编译成了你需要的dll。用csc  也可以;具体的你用 csc/?  查得到的。

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;
    using System.Drawing.Drawing2D;
    using System.Drawing.Text;namespace WindowsControlLibrary1
    {
     /// <summary>
     /// UserControl1 的摘要说明。
     /// </summary>
     public class UserControl1 : Button
     {
      /// <summary>
      /// 必需的设计器变量。
      /// </summary>
      private System.ComponentModel.Container components = null;
      private bool XiaCen=false;
      private bool mouseMove=false;
      private Color backColor;
      public UserControl1()
      {
       // 该调用是 Windows.Forms 窗体设计器所必需的。
       InitializeComponent();   // TODO: 在 InitComponent 调用后添加任何初始化
       backColor=this.backColor;
       //this.Text=this.ShowFocusCues.ToString();
      }  /// <summary>
      /// 清理所有正在使用的资源。
      /// </summary>
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if( components != null )
         components.Dispose();
       }
       base.Dispose( disposing );
      }  #region 组件设计器生成的代码
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器 
      /// 修改此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {
       // 
       // UserControl1
       // 
       this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.UserControl1_MouseUp);
       this.Paint += new System.Windows.Forms.PaintEventHandler(this.UserControl1_Paint);
       this.MouseEnter += new System.EventHandler(this.UserControl1_MouseEnter);
       this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.UserControl1_KeyUp);
       this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.UserControl1_KeyDown);
       this.BackColorChanged += new System.EventHandler(this.UserControl1_BackColorChanged);
       this.MouseLeave += new System.EventHandler(this.UserControl1_MouseLeave);
       this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.UserControl1_MouseDown);  }
      #endregion  
      
      protected GraphicsPath GetGraphicsPath(Rectangle rect)
      {
       GraphicsPath ClientPath = new System.Drawing.Drawing2D.GraphicsPath();
       if(rect.Width<=0)
       {
        rect.Width=1;
       }
       if(rect.Height<=0)
       {
        rect.Height=1;
       }
          
       ClientPath.AddArc(rect.Left,rect.Top,rect.Height,rect.Height,90f,180f);
       ClientPath.AddArc(rect.Right-rect.Height,rect.Top,rect.Height,rect.Height,270f,180f);
       ClientPath.CloseFigure();
       return ClientPath;
      }
       
      protected GraphicsPath GetGraphicsPath1(Rectangle rect)
      {
       GraphicsPath ClientPath = new System.Drawing.Drawing2D.GraphicsPath();
       if(rect.Width<=0)
       {
        rect.Width=1;
       }
       if(rect.Height<=0)
       {
        rect.Height=1;
       }
          
       ClientPath.AddArc(rect.Left,rect.Top,rect.Height,rect.Height,190f,80f);
       ClientPath.AddArc(rect.Right-rect.Height,rect.Top,rect.Height,rect.Height,270f,80f);
       ClientPath.CloseFigure();
       return ClientPath;
      }
      
      private void DrawYinYing(Graphics gr,bool xiacen)
      {
       Rectangle rect= this.ClientRectangle;
       rect.Inflate(-(rect.Width/10),-(rect.Height)/4);
       float bf1=rect.Width/100f;
       float bf2=rect.Height/100f;
       
       rect.Y=rect.Y+this.ClientRectangle.Height/4;
       if(xiacen)
       {
        rect.Y=rect.Y+4;
       }
       GraphicsPath path;
       
       for(int a=1;a<33;a++)
       {
        float bf3=bf1*a;
        float bf4=bf2*a;
        Rectangle rect1=rect;
        rect1.Inflate(-(int)bf3,-(int)bf4);
        path=GetGraphicsPath(rect1);
            
        int r=backColor.R;
        int g=backColor.G;
        int b=backColor.B;
        r=r+3*a;
        g=g+3*a;
        b=b+3*a;
        if(r>255) r=255;
        if(g>255) g=255;
        if(b>255) b=255;
        gr.FillPath(new SolidBrush(Color.FromArgb(r,g,b)),path);
       }
      }
      
      private void DrawGaoLiang(Graphics g,bool xiacen)
      {
       Rectangle rect= this.ClientRectangle;
       rect.Inflate(-4,-4);
       
       if(xiacen)
       {
        rect.Y=rect.Y+4;
       }
       GraphicsPath path=GetGraphicsPath1(rect);
       RectangleF rect1=path.GetBounds();
       rect1.Height=rect1.Height+1;
       g.FillPath(new LinearGradientBrush(rect1,
        Color.FromArgb(0xff,0xff,0xff,0xff),
        Color.FromArgb(0xff,backColor),LinearGradientMode.Vertical),path);
      }
      
      private void DrawText(Graphics g,bool xiacen)
      {
       Rectangle rect= this.ClientRectangle;
       Rectangle rect1= this.ClientRectangle;
       StringFormat stringFormat=new StringFormat();
       stringFormat.Alignment=StringAlignment.Center;
       stringFormat.LineAlignment=StringAlignment.Center;
       rect.Y=this.ClientRectangle.Height/5;
       if(xiacen)
       {
        rect.Y=rect.Y+4;
        rect1.Y=rect1.Y+4;
       }
       
       Font font=this.Font; 
       
       
       if(mouseMove)
       {
        font=new Font(this.Font,FontStyle.Underline); 
       }
       
       g.DrawString(this.Text,font,
        new SolidBrush(Color.FromArgb(0x66,backColor)),rect,stringFormat);
       g.DrawString(this.Text,font,new SolidBrush(this.ForeColor),rect1,stringFormat);
      }  private void UserControl1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
      {
       if(XiaCen==false)
       {
        XiaCen=true;
        this.Refresh();
       }
      }
      
      private void UserControl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
      {
       if(XiaCen==true)
       {
        XiaCen=false;
        this.Refresh();
       }
      }  private void UserControl1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
      {
       
       
      }
      
      protected override void OnPaint(PaintEventArgs e)
      {
       
       base.OnPaint(e);
       e.Graphics.FillRectangle(new SolidBrush(backColor),0,0,this.Width,this.Height);
       e.Graphics.SmoothingMode=SmoothingMode.HighQuality;
       e.Graphics.TextRenderingHint=TextRenderingHint.AntiAliasGridFit;
       Rectangle rect=new Rectangle(0,0,this.Width,this.Height);
       GraphicsPath ClientPath=GetGraphicsPath(rect);
       e.Graphics.FillPath(new SolidBrush(backColor),ClientPath);
       this.Region=new System.Drawing.Region(ClientPath);
       DrawYinYing(e.Graphics,XiaCen);
       DrawGaoLiang(e.Graphics,XiaCen);
       DrawText(e.Graphics,XiaCen);
       
       if(this.Focused)
       {
        e.Graphics.DrawPath(new Pen(Color.FromArgb(0x22,0xff,0xff,0xff), 3), ClientPath); 
       }
       
      }  
     
      private void UserControl1_BackColorChanged(object sender, System.EventArgs e)
      {
       int r=BackColor.R;
       int g=BackColor.G;
       int b=BackColor.B;
       r=r+0x22;
       g=g+0x22;
       b=b+0x22;
       if(r>255) r=255;
       if(g>255) g=255;
       if(b>255) b=255;
       backColor=Color.FromArgb(r,g,b);
      }  private void UserControl1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
      {
       if(XiaCen==false && e.KeyCode==Keys.Space)
       {
        XiaCen=true;
        this.Refresh();
       }
      }  private void UserControl1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
      {
       if(XiaCen==true && e.KeyCode==Keys.Space)
       {
        XiaCen=false;
        this.Refresh();
       }
      }  private void UserControl1_MouseEnter(object sender, System.EventArgs e)
      {
       if(mouseMove==false)
       {
        mouseMove=true;
        this.Refresh();
       }
      }  private void UserControl1_MouseLeave(object sender, System.EventArgs e)
      {
       if(mouseMove==true)
       {
        mouseMove=false;
        this.Refresh();
       }
      }
      
     }
    }
      

  2.   

    完全没有问题,.net中的assebly就是你要的那种控件,另外还能够做到用属性dialog设置。
    这些东西在.net中都能够很方便的实现,给你看一个在这方面很全面的帖子.里面还有source code,相信对你肯定很有帮助。http://www.codeproject.com/cs/miscctrl/tooltips.asp
      

  3.   

    msdn:http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopingwebformscontrols.asp
      

  4.   

    下面是一个自做的控件代码
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;namespace CompositeControl
    {
    /// <summary>
    /// UserControl1 的摘要说明。
    /// </summary>
    public class ctlFullName : System.Windows.Forms.UserControl
    {
    private System.Windows.Forms.TextBox txtFirstName;
    private System.Windows.Forms.TextBox txtMiddleName;
    private System.Windows.Forms.TextBox txtLastName;
    private System.Windows.Forms.Label lblLastName;
    private System.Windows.Forms.Label lblFirstName;
    private System.Windows.Forms.Label lblMiddleName;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public ctlFullName()
    {
    // 该调用是 Windows.Forms 窗体设计器所必需的。
    InitializeComponent(); // TODO: 在 InitComponent 调用后添加任何初始化 } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if( components != null )
    components.Dispose();
    }
    base.Dispose( disposing );
    } #region 组件设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器 
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.txtFirstName = new System.Windows.Forms.TextBox();
    this.txtMiddleName = new System.Windows.Forms.TextBox();
    this.txtLastName = new System.Windows.Forms.TextBox();
    this.lblLastName = new System.Windows.Forms.Label();
    this.lblFirstName = new System.Windows.Forms.Label();
    this.lblMiddleName = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // txtFirstName
    // 
    this.txtFirstName.Location = new System.Drawing.Point(8, 40);
    this.txtFirstName.Name = "txtFirstName";
    this.txtFirstName.Size = new System.Drawing.Size(208, 21);
    this.txtFirstName.TabIndex = 0;
    this.txtFirstName.Text = "textBox1";
    // 
    // txtMiddleName
    // 
    this.txtMiddleName.Location = new System.Drawing.Point(8, 120);
    this.txtMiddleName.Name = "txtMiddleName";
    this.txtMiddleName.Size = new System.Drawing.Size(208, 21);
    this.txtMiddleName.TabIndex = 1;
    this.txtMiddleName.Text = "textBox2";
    // 
    // txtLastName
    // 
    this.txtLastName.Location = new System.Drawing.Point(8, 200);
    this.txtLastName.Name = "txtLastName";
    this.txtLastName.Size = new System.Drawing.Size(208, 21);
    this.txtLastName.TabIndex = 2;
    this.txtLastName.Text = "textBox3";
    // 
    // lblLastName
    // 
    this.lblLastName.ForeColor = System.Drawing.Color.Red;
    this.lblLastName.Location = new System.Drawing.Point(8, 176);
    this.lblLastName.Name = "lblLastName";
    this.lblLastName.Size = new System.Drawing.Size(100, 16);
    this.lblLastName.TabIndex = 3;
    this.lblLastName.Text = "LastName";
    // 
    // lblFirstName
    // 
    this.lblFirstName.ForeColor = System.Drawing.Color.Red;
    this.lblFirstName.Location = new System.Drawing.Point(8, 24);
    this.lblFirstName.Name = "lblFirstName";
    this.lblFirstName.Size = new System.Drawing.Size(72, 16);
    this.lblFirstName.TabIndex = 4;
    this.lblFirstName.Text = "FirstName";
    // 
    // lblMiddleName
    // 
    this.lblMiddleName.ForeColor = System.Drawing.Color.Red;
    this.lblMiddleName.Location = new System.Drawing.Point(8, 96);
    this.lblMiddleName.Name = "lblMiddleName";
    this.lblMiddleName.Size = new System.Drawing.Size(100, 16);
    this.lblMiddleName.TabIndex = 5;
    this.lblMiddleName.Text = "MiddleName";
    // 
    // UserControl1
    // 
    this.Controls.Add(this.lblMiddleName);
    this.Controls.Add(this.lblFirstName);
    this.Controls.Add(this.lblLastName);
    this.Controls.Add(this.txtLastName);
    this.Controls.Add(this.txtMiddleName);
    this.Controls.Add(this.txtFirstName);
    this.ForeColor = System.Drawing.Color.Red;
    this.Name = "UserControl1";
    this.Size = new System.Drawing.Size(232, 240);
    this.Load += new System.EventHandler(this.UserControl1_Load);
    this.ResumeLayout(false); }
    #endregion public string FirstName
    {
    get
    {
    return txtFirstName.Text;
    }
    set
    {
    txtFirstName.Text=value;
    }
    } public string MiddleName
    {
    get
    {
    return txtMiddleName.Text;
    }
    set
    {
    txtMiddleName.Text=value;
    }
    } public string LastName
    {
    get
    {
    return txtLastName.Text;
    }
    set
    {
    txtLastName.Text=value;
    }
    }
    public System.Drawing.Font LableFont
    {
    get
    {
    return lblFirstName.Font;
    }
    set
    {
    lblFirstName.Font=value;
    lblMiddleName.Font=value;
    lblLastName.Font=value;
    }
    }
    public override string ToString()
    {
    return (txtFirstName.Text + " " + txtMiddleName.Text.Trim() + " " + txtLastName.Text.Trim());
    } private void UserControl1_Load(object sender, System.EventArgs e)
    {

    }
    }
    }
      

  5.   

    下面是一个用户控件的例子,可以单独编译成dll,然后就可以用了。
    ======================================
    用户控件代码
    ======================================
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Windows.Forms;namespace ZZTestForm
    {
    //定义事件代理
    public delegate void TextBoxChangedHandle(string message);
    /// <summary>
    /// UserControl1 的摘要说明。
    /// </summary>
    public class UserControl1 : System.Windows.Forms.UserControl
    {
    //定义事件
    public event TextBoxChangedHandle TextBoxChanged;
    private System.Windows.Forms.TextBox textBox1;
    /// <summary> 
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public UserControl1()
    {
    InitializeComponent();
    }
    /// <summary> 
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region 组件设计器生成的代码
    /// <summary> 
    /// 设计器支持所需的方法 - 不要使用代码编辑器 
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(20, 32);
    this.textBox1.Name = "textBox1";
    this.textBox1.TabIndex = 0;
    this.textBox1.Text = "textBox1";
    this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
    // 
    // UserControl1
    // 
    this.Controls.Add(this.textBox1);
    this.Name = "UserControl1";
    this.Size = new System.Drawing.Size(150, 96);
    this.ResumeLayout(false); }
    #endregion private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
    //激发事件
    TextBoxChanged(this.textBox1.Text);
    }
    }
    }
      

  6.   

    这个是对上面的控件的使用
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace ZZTestForm
    {
    /// <summary>
    /// MainForm 的摘要说明。
    /// </summary>
    public class MainForm : System.Windows.Forms.Form
    {
    private ZZTestForm.UserControl1 userControl11;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public MainForm()
    {
    InitializeComponent();
    //注册用户控件事件
    this.userControl11.TextBoxChanged +=new TextBoxChangedHandle(userControl11_TextBoxChanged); }

    /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new MainForm());
    }
    #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.userControl11 = new ZZTestForm.UserControl1();
    this.SuspendLayout();
    // 
    // userControl11
    // 
    this.userControl11.Location = new System.Drawing.Point(108, 68);
    this.userControl11.Name = "userControl11";
    this.userControl11.Size = new System.Drawing.Size(150, 96);
    this.userControl11.TabIndex = 0;
    // 
    // MainForm
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(376, 249);
    this.Controls.Add(this.userControl11);
    this.Name = "MainForm";
    this.Text = "MainForm";
    this.ResumeLayout(false); }
    #endregion
    /// <summary>
    /// 控件事件处理
    /// </summary>
    /// <param name="message"></param>
    private void userControl11_TextBoxChanged(string message)
    {
    MessageBox.Show("你改变了用户控件中 文本框的值:"+message);
    }
    }
    }