如何用c#写动态添加按钮的鼠标事件

解决方案 »

  1.   

    button.Click += new System.EventHandler(单击时间的函数);
      

  2.   

    我还要得到这个 button的相关信息,如TabIndex因为我这个button是添加在panel里的,也要得panel的信息哪位帮帮忙
      

  3.   

    这些panel,button都是动态添加的
      

  4.   

    你把你动态添加的panel,button的代码段贴出来,参考后再解答!
      

  5.   

    private void InitializeGroup(int groupNum)
    {
    for(int i = 1; i < 3; i++)
    {
    m_panel.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(64)), ((System.Byte)(64)));
    m_panel.Location = new System.Drawing.Point(200, 64 + (i-1)*100);
    m_panel.Name = "panel" + i.ToString();
    m_panel.Size = new System.Drawing.Size(200, 200);
    m_panel.TabIndex = i;
    this.Controls.Add(m_panel); InitializeSeat(m_seatNum);
    }

    }
    private void InitializeSeat(int seatNum)
    {
    for(int i = 1; i < seatNum + 1; i++)
    {
    Button button = new Button();
    button.Location = new System.Drawing.Point(16, 16 + i*48);
    button.Name = "button" + i.ToString();
    button.TabIndex = 35;
    button.Text = "";
    this.Controls.Add(button); button.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button_MouseDown); m_panel.Controls.Add(button); }
    }
    private void button_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(e.Button == MouseButtons.Right)
    MessageBox.Show("ssaa");
    }在此事件中我要针对点的哪个button做出相关操作