自定义控件里有一个 label ,我想调用的时候点击label就这行这个控件的click所绑定的事件,请问应该怎么实现啊?谢谢!

解决方案 »

  1.   

    编译成DLL 调用完全可以的呀,你是不是没写过自定义控件呀。访问我的博客 程序员日记 http://www.ideaext.com
      

  2.   

    this.Load += new System.EventHandler(this.label_Click);
      

  3.   

    我自定义一个控件(MyControl),里面有个一label,我想单击这个MyControl里的label时,执行MyControl的Click绑定的事件,请问应该怎么实现啊?谢谢大侠!
      

  4.   

    自定义控件继承Control类,一般都要自己实现 OnPaint 方法来绘制外观的。
    按你的要求,MyControl 里边又放了一个Control:label,
    我想你应该用 用户控件,它继承UserControl类。
    新建一个类,复制下面代码,即可生成所需功能控件。
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication3
    {
        public partial class UserControl1 : UserControl
        {
            public UserControl1()
            {
                InitializeComponent();        }        private System.ComponentModel.IContainer components = null;        protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        private void InitializeComponent()
            {
                this.label1 = new System.Windows.Forms.Label();
                this.SuspendLayout();
                // 
                // label1
                // 
                this.label1.AutoSize = true;
                this.label1.Location = new System.Drawing.Point(20, 27);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(41, 12);
                this.label1.TabIndex = 0;
                this.label1.Text = "click this ";
                this.label1.Click += new System.EventHandler(this.label1_Click);
                // 
                // UserControl1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.Controls.Add(this.label1);
                this.Name = "UserControl1";
                this.Click += new System.EventHandler(this.UserControl1_Click);
                this.ResumeLayout(false);
                this.PerformLayout();        }        #endregion        private System.Windows.Forms.Label label1;        private void label1_Click(object sender, EventArgs e)
            {
                UserControl1_Click(sender, e);
            }        private void UserControl1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("control is click");
            }
        }
    }
      

  5.   

    可能是我说的不是很清楚,我自定义一个控件(MyControl),里面有个一label!在用的时候,我把自定义控件(MyControl)拖到窗体上,但是我怎么才能绑定label的Click事件啊?谢谢!