本文整理汇总了C#中System.Windows.Forms.ToolBarButtonClickEventHandler代理的典型用法代码示例。如果您正苦于以下问题:C# ToolBarButtonClickEventHandler代理的具体用法?C# ToolBarButtonClickEventHandler怎么用?C# ToolBarButtonClickEventHandler使用的例子?那么恭喜您, 这里精选的代理代码示例或许可以为您提供帮助。
ToolBarButtonClickEventHandler代理属于System.Windows.Forms命名空间,在下文中一共展示了ToolBarButtonClickEventHandler代理的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeMyToolBar
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);
}
private 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: new ToolBarButtonClickEventHandler
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class TextBoxWithToolBar: Form
{
TextBox txtbox = new TextBox();
MenuItem miEditCut, miEditCopy, miEditPaste;
ToolBarButton tbbCut, tbbCopy, tbbPaste;
public static void Main()
{
System.Threading.Thread.CurrentThread.ApartmentState =
System.Threading.ApartmentState.STA;
Application.Run(new TextBoxWithToolBar());
}
public TextBoxWithToolBar()
{
txtbox.Parent = this;
txtbox.Dock = DockStyle.Fill;
txtbox.Multiline = true;
txtbox.ScrollBars = ScrollBars.Both;
txtbox.AcceptsTab = true;
Bitmap bm = new Bitmap(GetType(), "TextBoxWithToolBar.bmp");
ImageList imglst = new ImageList();
imglst.Images.AddStrip(bm);
imglst.TransparentColor = Color.Cyan;
ToolBar tbar = new ToolBar();
tbar.Parent = this;
tbar.ImageList = imglst;
tbar.ShowToolTips = true;
tbar.ButtonClick += new ToolBarButtonClickEventHandler(ToolBarOnClick);
Menu = new MainMenu();
MenuItem mi = new MenuItem("&Edit");
mi.Popup += new EventHandler(MenuEditOnPopup);
Menu.MenuItems.Add(mi);
miEditCut = new MenuItem("Cu&t");
miEditCut.Click += new EventHandler(MenuEditCutOnClick);
miEditCut.Shortcut = Shortcut.CtrlX;
Menu.MenuItems[0].MenuItems.Add(miEditCut);
tbbCut = new ToolBarButton();
tbbCut.ImageIndex = 4;
tbbCut.ToolTipText = "Cut";
tbbCut.Tag = miEditCut;
tbar.Buttons.Add(tbbCut);
miEditCopy = new MenuItem("&Copy");
miEditCopy.Click += new EventHandler(MenuEditCopyOnClick);
miEditCopy.Shortcut = Shortcut.CtrlC;
Menu.MenuItems[0].MenuItems.Add(miEditCopy);
tbbCopy = new ToolBarButton();
tbbCopy.ImageIndex = 5;
tbbCopy.ToolTipText = "Copy";
tbbCopy.Tag = miEditCopy;
tbar.Buttons.Add(tbbCopy);
miEditPaste = new MenuItem("&Paste");
miEditPaste.Click += new EventHandler(MenuEditPasteOnClick);
miEditPaste.Shortcut = Shortcut.CtrlV;
Menu.MenuItems[0].MenuItems.Add(miEditPaste);
tbbPaste = new ToolBarButton();
tbbPaste.ImageIndex = 6;
tbbPaste.ToolTipText = "Paste";
tbbPaste.Tag = miEditPaste;
tbar.Buttons.Add(tbbPaste);
Timer timer = new Timer();
timer.Interval = 250;
timer.Tick += new EventHandler(TimerOnTick);
timer.Start();
}
void MenuEditOnPopup(object obj, EventArgs ea)
{
miEditCut.Enabled =
miEditCopy.Enabled = (txtbox.SelectionLength > 0);
miEditPaste.Enabled =
Clipboard.GetDataObject().GetDataPresent(typeof(string));
}
void TimerOnTick(object obj, EventArgs ea)
{
tbbCut.Enabled =
tbbCopy.Enabled = (txtbox.SelectionLength) > 0;
tbbPaste.Enabled =
Clipboard.GetDataObject().GetDataPresent(typeof(string));
}
void ToolBarOnClick(object obj, ToolBarButtonClickEventArgs tbbcea)
{
ToolBarButton tbb = tbbcea.Button;
MenuItem mi = (MenuItem) tbb.Tag;
mi.PerformClick();
}
void MenuEditCutOnClick(object obj, EventArgs ea)
{
txtbox.Cut();
}
void MenuEditCopyOnClick(object obj, EventArgs ea)
{
txtbox.Copy();
}
void MenuEditPasteOnClick(object obj, EventArgs ea)
{
txtbox.Paste();
}
}