你想将其中的button的click事件作为你的用户空间的click事件,公开?

解决方案 »

  1.   

    可参考下面的做法:
    tr.MouseDown+=new System.Windows.Forms.MouseEventHandler(this.trMouseDown);
    public void trMouseDown(object sender ,System.Windows.Forms.MouseEventArgs e)
    {
    ((TreeView)sender).SelectedNode=((TreeView)sender).GetNodeAt(e.X,e.Y);
    }
      

  2.   

    回复人: moonewxp(母牛) 是的
      

  3.   

    //*在你的UserControl中,
    public event EventHandler TextBoxClick;//这里是自定义TextBox的Click事件
    //...
    this.TextBox.Click += new EventHandler(TextBox_Click);//这里订阅事件
    //...
    private void TextBox_Click(object sender,System.EventArgs e)//这里处理事件
    {
      if (TextBoxClick!= null)
      {
        TextBoxClick(sender,e);//引发事件
      }
    }
    //*在外部调用时
    UserControl.TextBoxClick += new EventHandler(TextBoxClick);//处理事件
    private void TextBoxClick(object sender,System.EventArgs e)//这里处理事件
    {
      //...
    }
      

  4.   

    试试这样可行不?
    [Category("Action")]
    public event EventHandler Click;
      

  5.   

    用户控件代码:
    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);
    }
    }
    }
    主窗体代码:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace ZZTestForm
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private ZZTestForm.UserControl1 userControl11;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    InitializeComponent();
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.userControl11 = new ZZTestForm.UserControl1();
    this.SuspendLayout();
    // 
    // userControl11
    // 
    this.userControl11.Location = new System.Drawing.Point(96, 48);
    this.userControl11.Name = "userControl11";
    this.userControl11.Size = new System.Drawing.Size(150, 96);
    this.userControl11.TabIndex = 0;
    this.userControl11.TextBoxChanged += new ZZTestForm.TextBoxChangedHandle(this.userControl11_TextBoxChanged);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(332, 217);
    this.Controls.Add(this.userControl11);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void userControl11_TextBoxChanged(string message)
    {
    MessageBox.Show("你改变了用户控件中TextBox的值:"+message);
    } }
    }
      

  6.   

    按照 zhzuo(秋枫)方法已基本实现其功能
    但略有不足的是无法在空间中直接双击引发该事件的处理(像Button那样)
    如果有解决办法的话请给我留言