看这段代码 可能又帮助!public void InitializeMyToolBar() { // Create and initialize the ToolBar and ToolBarButton controls. toolBar1 = new ToolBar(); ToolBarButton toolBarButton1 = new ToolBarButton(); ToolBarButton toolBarButton2 = new ToolBarButton(); ToolBarButton toolBarButton3 = new ToolBarButton();
// Set the Text properties of the ToolBarButton controls. toolBarButton1.Text = "Open"; toolBarButton2.Text = "Save"; toolBarButton3.Text = "Print";
// Add the ToolBarButton controls to the ToolBar. toolBar1.Buttons.Add(toolBarButton1); toolBar1.Buttons.Add(toolBarButton2); toolBar1.Buttons.Add(toolBarButton3);
// Add the event-handler delegate. toolBar1.ButtonClick += new ToolBarButtonClickEventHandler ( this.toolBar1_ButtonClick);
// Add the ToolBar to the Form. Controls.Add(toolBar1); }
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; } }
[VB] Protected Sub Control_Click(sender As Object, e As EventArgs) _ Handles Button1.Click, MenuItem1.Click[C#] this.Button1.Click += New EventHandler(this.Control_Click); this.MenuItem1.Click += New EventHandler(this.Control_Click);protected void Control_Click(Object sender, EventArgs e) { }
楼上的两位,谢谢你们,我的意思是,能不能这样,就是在deng_kun的代码 中toolBar1_ButtonClick里面, .... case 0: menuItem1_Click(); break; case 1: menuItem_Click(); break; ....... 这样来做行不行? 如果只是button的话,用ninputer的方法就可以啦.
{
// Create and initialize the ToolBar and ToolBarButton controls.
toolBar1 = new ToolBar();
ToolBarButton toolBarButton1 = new ToolBarButton();
ToolBarButton toolBarButton2 = new ToolBarButton();
ToolBarButton toolBarButton3 = new ToolBarButton();
// Set the Text properties of the ToolBarButton controls.
toolBarButton1.Text = "Open";
toolBarButton2.Text = "Save";
toolBarButton3.Text = "Print";
// Add the ToolBarButton controls to the ToolBar.
toolBar1.Buttons.Add(toolBarButton1);
toolBar1.Buttons.Add(toolBarButton2);
toolBar1.Buttons.Add(toolBarButton3);
// Add the event-handler delegate.
toolBar1.ButtonClick += new ToolBarButtonClickEventHandler (
this.toolBar1_ButtonClick);
// Add the ToolBar to the Form.
Controls.Add(toolBar1);
}
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 Sub Control_Click(sender As Object, e As EventArgs) _
Handles Button1.Click, MenuItem1.Click[C#]
this.Button1.Click += New EventHandler(this.Control_Click);
this.MenuItem1.Click += New EventHandler(this.Control_Click);protected void Control_Click(Object sender, EventArgs e)
{
}
中toolBar1_ButtonClick里面,
....
case 0:
menuItem1_Click();
break;
case 1:
menuItem_Click();
break;
....... 这样来做行不行?
如果只是button的话,用ninputer的方法就可以啦.
menuItem1_Click();
return;
break;
完全可以