操作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; } }
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;
}
}
ms-help://MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemWindowsFormsToolBarClassTopic.htm
private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
if(e.Button == this.toolBarButton1)
{
...
}
else if(e.Button == this.toolBarButton2)
{
...
}
...
}
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;
}
}
}这种方法是最好的