好像在click时间里可以得到button对象,不知你要什么

解决方案 »

  1.   

    操作ToolBar的代码如下,参考
     protected void toolBar1_ButtonClick (
                             Object sender, 
                             ToolBarButtonClickEventArgs e)
     {
       // Evaluate the Button property to determine which button was clicked.
       switch(toolBar1.Buttons.IndexOf(e.Button))
       {
          case 0:
             openFileDialog1.ShowDialog();
             // Insert code to open the file.
             break; 
          case 1:
             saveFileDialog1.ShowDialog();
             // Insert code to save the file.
             break; 
          case 2:
             printDialog1.ShowDialog();
             // Insert code to print the file.    
             break; 
        }
     }
      

  2.   

    详细参考
    ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemWindowsFormsToolBarClassTopic.htm
      

  3.   

    我就直接用 if
    private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
    {
        if(e.Button == this.toolBarButton1)
        {
             ...
        }
        else if(e.Button == this.toolBarButton2)
        {
             ...
        }
        ...
    }
      

  4.   

    Type t = this.GetType();
    FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
    for (int i=0;i<fields.Length;i++)
    { if (fields[i].FieldType.Name == "ToolBarButton")
    {
    ToolBarButton button = (ToolBarButton)fields[i].GetValue(this);
    if (e.Button.Equals(button))
    {
    MessageBox.Show(fields[i].Name);
    break;
    }
    }
    }这种方法是最好的