Csharp/C Sharp by API/System.Windows.Controls/ToolBar — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:11, 26 мая 2010
Содержание
ToolBar.BorderStyle
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class ToolBarButtonBorderStyle : System.Windows.Forms.Form
{
private ImageList toolBarIcons;
private ToolBarButton tbExitButton;
private ToolBarButton tbSaveButton;
private ToolBar toolBar;
private System.ruponentModel.Container components = null;
public ToolBarButtonBorderStyle()
{
this.ruponents = new System.ruponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
toolBar = new ToolBar();
toolBarIcons = new ImageList();
tbSaveButton = new ToolBarButton();
tbExitButton = new ToolBarButton();
tbSaveButton.ImageIndex = 0;
tbExitButton.ImageIndex = 1;
toolBar.ImageList = toolBarIcons;
toolBar.Size = new System.Drawing.Size(272, 28);
toolBar.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
toolBar.Buttons.AddRange(new ToolBarButton[] {tbSaveButton, tbExitButton});
toolBar.ButtonClick += new ToolBarButtonClickEventHandler(ToolBar_Clicked);
toolBarIcons.ImageSize = new System.Drawing.Size(32, 32);
toolBarIcons.Images.Add(new Icon("filesave.ico"));
toolBarIcons.Images.Add(new Icon("fileexit.ico"));
toolBarIcons.ColorDepth = ColorDepth.Depth16Bit;
toolBarIcons.TransparentColor = System.Drawing.Color.Transparent;
this.Controls.Add(toolBar);
}
[STAThread]
static void Main()
{
Application.Run(new ToolBarButtonBorderStyle());
}
private void ToolBar_Clicked(object sender, ToolBarButtonClickEventArgs e)
{
MessageBox.Show(e.Button.ToolTipText);
}
}
ToolBar.ButtonClick
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class ToolBarLinkedWithMenu : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mnuNew;
private System.Windows.Forms.MenuItem mnuFile;
private System.Windows.Forms.MenuItem mnuFileOpen;
private System.Windows.Forms.MenuItem mnuFileClose;
private System.Windows.Forms.MenuItem mnuFileSave;
private System.Windows.Forms.MenuItem mnuFileSaveAs;
private System.Windows.Forms.MenuItem mnuEdit;
private System.Windows.Forms.MenuItem mnuEditCopy;
private System.Windows.Forms.MenuItem mnuEditPaste;
private System.Windows.Forms.MenuItem mnuOption1;
private System.Windows.Forms.MenuItem mnuOption2;
private System.Windows.Forms.MenuItem mnuOption3;
private System.Windows.Forms.MenuItem mnuROption1;
private System.Windows.Forms.MenuItem mnuROption2;
private System.Windows.Forms.MenuItem mnuROption3;
private System.Windows.Forms.MenuItem mnuWindow;
private System.Windows.Forms.MenuItem mnuOptions;
private System.Windows.Forms.MenuItem mnuRadioOptions;
private System.Windows.Forms.MenuItem mnuMenu1;
private System.Windows.Forms.MenuItem mnuMenu11;
private System.Windows.Forms.MenuItem mnuMenu12;
private System.Windows.Forms.MenuItem mnuMenu13;
private System.Windows.Forms.MenuItem mnuMenu14;
private System.Windows.Forms.MenuItem mnuMenu2;
private System.Windows.Forms.MenuItem mnuMenu21;
private System.Windows.Forms.MenuItem mnuMenu22;
private System.Windows.Forms.MenuItem mnuMenu23;
private System.Windows.Forms.MenuItem mnuMenu24;
private System.Windows.Forms.MenuItem mnuMerge;
private System.Windows.Forms.MenuItem mnuODShazam;
private string[] files = { "YourFile.bmp", "YourFile.bmp" };
private System.Windows.Forms.MenuItem mnuODVote;
private System.Windows.Forms.MenuItem mnuSpecial;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ImageList imgListFileButtons;
private System.ruponentModel.Container components = null;
public ToolBarLinkedWithMenu()
{
InitializeComponent();
CreateImageList();
InitializeToolbar();
}
private void InitializeToolbar()
{
toolBar1 = new ToolBar();
toolBar1.ImageList = imgListFileButtons;
ToolBarButton btnNew = new ToolBarButton();
btnNew.Tag = mnuNew;
btnNew.Enabled = true;
btnNew.ImageIndex = 0; // new file
btnNew.Pushed = false;
btnNew.Style = ToolBarButtonStyle.PushButton;
btnNew.Text= "New";
btnNew.ToolTipText = "New document";
btnNew.Visible = true;
toolBar1.Buttons.Add(btnNew);
ToolBarButton btnOpen = new ToolBarButton();
btnOpen.Tag = mnuFileOpen;
btnOpen.Enabled = true;
btnOpen.ImageIndex = 1; // open file
btnOpen.Pushed = false;
btnOpen.Style = ToolBarButtonStyle.PushButton;
btnOpen.Text = "Open";
btnOpen.ToolTipText = "Open a document";
btnOpen.Visible = true;
toolBar1.Buttons.Add(btnOpen);
ToolBarButton btnSave = new ToolBarButton();
btnSave.Tag = mnuFileSave;
btnSave.Enabled = true;
btnSave.ImageIndex = 3; // save file
btnSave.Pushed = false;
btnSave.Style = ToolBarButtonStyle.PushButton;
btnSave.Text = "Save";
btnSave.ToolTipText = "Save document";
btnSave.Visible = true;
toolBar1.Buttons.Add(btnSave);
ComboBox cb = new ComboBox();
cb.Left = 150;
cb.Top = 5;
cb.Items.Add("Alabama");
cb.Items.Add("Alaska");
cb.Items.Add("Arizona");
cb.Items.Add("Arkansas");
ToolTip tip = new ToolTip();
tip.AutomaticDelay = 500;
// tip.AutoPopDelay = 10 times AutomaticDelay
// tip.InitialDelay = AutomaticDelay
//tip.ReshowDelay = 1/5 AutomaticDelay
tip.ShowAlways = true; // display even if control is disabled
tip.SetToolTip(cb,"Pick a state");
toolBar1.Controls.Add(cb);
toolBar1.Parent = this;
toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
toolBar1.DropDownArrows = true;
toolBar1.Name = "toolBar1";
toolBar1.ShowToolTips = true;
toolBar1.Size = new System.Drawing.Size(440, 41);
toolBar1.TabIndex = 1;
toolBar1.ButtonClick +=
new System.Windows.Forms.ToolBarButtonClickEventHandler(
toolBar1_ButtonClick);
}
private void CreateImageList()
{
imgListFileButtons = new ImageList();
Image img;
String[] arFiles = { "1.ico", "2.ico", "3.ico", "4.ico" };
for (int i = 0; i < arFiles.Length; i++)
{
img = Image.FromFile(arFiles[i]);
imgListFileButtons.Images.Add(img);
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.mnuFile = new System.Windows.Forms.MenuItem();
this.mnuNew = new System.Windows.Forms.MenuItem();
this.mnuFileOpen = new System.Windows.Forms.MenuItem();
this.mnuFileClose = new System.Windows.Forms.MenuItem();
this.mnuFileSave = new System.Windows.Forms.MenuItem();
this.mnuFileSaveAs = new System.Windows.Forms.MenuItem();
this.mnuEdit = new System.Windows.Forms.MenuItem();
this.mnuEditCopy = new System.Windows.Forms.MenuItem();
this.mnuEditPaste = new System.Windows.Forms.MenuItem();
this.mnuOptions = new System.Windows.Forms.MenuItem();
this.mnuOption1 = new System.Windows.Forms.MenuItem();
this.mnuOption2 = new System.Windows.Forms.MenuItem();
this.mnuOption3 = new System.Windows.Forms.MenuItem();
this.mnuRadioOptions = new System.Windows.Forms.MenuItem();
this.mnuROption1 = new System.Windows.Forms.MenuItem();
this.mnuROption2 = new System.Windows.Forms.MenuItem();
this.mnuROption3 = new System.Windows.Forms.MenuItem();
this.mnuWindow = new System.Windows.Forms.MenuItem();
this.mnuMenu1 = new System.Windows.Forms.MenuItem();
this.mnuMenu11 = new System.Windows.Forms.MenuItem();
this.mnuMenu12 = new System.Windows.Forms.MenuItem();
this.mnuMenu13 = new System.Windows.Forms.MenuItem();
this.mnuMenu14 = new System.Windows.Forms.MenuItem();
this.mnuMerge = new System.Windows.Forms.MenuItem();
this.mnuMenu2 = new System.Windows.Forms.MenuItem();
this.mnuMenu21 = new System.Windows.Forms.MenuItem();
this.mnuMenu22 = new System.Windows.Forms.MenuItem();
this.mnuMenu23 = new System.Windows.Forms.MenuItem();
this.mnuMenu24 = new System.Windows.Forms.MenuItem();
this.mnuSpecial = new System.Windows.Forms.MenuItem();
this.mnuODVote = new System.Windows.Forms.MenuItem();
this.mnuODShazam = new System.Windows.Forms.MenuItem();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuFile,
this.mnuEdit,
this.mnuOptions,
this.mnuRadioOptions,
this.mnuSpecial,
this.mnuWindow,
this.mnuMenu1,
this.mnuMenu2});
//
// mnuFile
//
this.mnuFile.Index = 0;
this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuNew,
this.mnuFileOpen,
this.mnuFileClose,
this.mnuFileSave,
this.mnuFileSaveAs});
this.mnuFile.Text = "File";
//
// mnuNew
//
this.mnuNew.Index = 0;
this.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.mnuNew.Text = "&New";
//
// mnuFileOpen
//
this.mnuFileOpen.Index = 1;
this.mnuFileOpen.Text = "Open";
//
// mnuFileClose
//
this.mnuFileClose.Index = 2;
this.mnuFileClose.Text = "Close";
//
// mnuFileSave
//
this.mnuFileSave.Index = 3;
this.mnuFileSave.Text = "Save";
//
// mnuFileSaveAs
//
this.mnuFileSaveAs.Index = 4;
this.mnuFileSaveAs.Text = "Save&As";
//
// mnuEdit
//
this.mnuEdit.Index = 1;
this.mnuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuEditCopy,
this.mnuEditPaste});
this.mnuEdit.Text = "Edit";
//
// mnuEditCopy
//
this.mnuEditCopy.Index = 0;
this.mnuEditCopy.Text = "&Copy";
//
// mnuEditPaste
//
this.mnuEditPaste.Index = 1;
this.mnuEditPaste.Text = "Paste";
//
// mnuOptions
//
this.mnuOptions.Index = 2;
this.mnuOptions.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuOption1,
this.mnuOption2,
this.mnuOption3});
this.mnuOptions.Text = "Options";
//
// mnuOption1
//
this.mnuOption1.Index = 0;
this.mnuOption1.Text = "Option1";
//
// mnuOption2
//
this.mnuOption2.Index = 1;
this.mnuOption2.Text = "Option2";
//
// mnuOption3
//
this.mnuOption3.Index = 2;
this.mnuOption3.Text = "Option3";
//
// mnuRadioOptions
//
this.mnuRadioOptions.Index = 3;
this.mnuRadioOptions.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuROption1,
this.mnuROption2,
this.mnuROption3});
this.mnuRadioOptions.Text = "Radio Options";
//
// mnuROption1
//
this.mnuROption1.Index = 0;
this.mnuROption1.RadioCheck = true;
this.mnuROption1.Text = "Radio Option 1";
//
// mnuROption2
//
this.mnuROption2.Index = 1;
this.mnuROption2.RadioCheck = true;
this.mnuROption2.Text = "Radio Option 2";
//
// mnuROption3
//
this.mnuROption3.Index = 2;
this.mnuROption3.RadioCheck = true;
this.mnuROption3.Text = "Radio Option 3";
//
// mnuWindow
//
this.mnuWindow.Index = 5;
this.mnuWindow.MdiList = true;
this.mnuWindow.MergeOrder = 99;
this.mnuWindow.Text = "&Window";
//
// mnuMenu1
//
this.mnuMenu1.Index = 6;
this.mnuMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuMenu11,
this.mnuMenu12,
this.mnuMenu13,
this.mnuMenu14,
this.mnuMerge});
this.mnuMenu1.Text = "Menu 1";
//
// mnuMenu11
//
this.mnuMenu11.Index = 0;
this.mnuMenu11.MergeOrder = 1;
this.mnuMenu11.Text = "Menu 1.1";
//
// mnuMenu12
//
this.mnuMenu12.Index = 1;
this.mnuMenu12.MergeOrder = 2;
this.mnuMenu12.Text = "Menu 1.2";
//
// mnuMenu13
//
this.mnuMenu13.Index = 2;
this.mnuMenu13.MergeOrder = 3;
this.mnuMenu13.Text = "Menu 1.3";
//
// mnuMenu14
//
this.mnuMenu14.Index = 3;
this.mnuMenu14.MergeOrder = 4;
this.mnuMenu14.Text = "Menu 1.4";
//
// mnuMerge
//
this.mnuMerge.Index = 4;
this.mnuMerge.MergeOrder = 99;
this.mnuMerge.Text = "Merge!";
//
// mnuMenu2
//
this.mnuMenu2.Index = 7;
this.mnuMenu2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuMenu21,
this.mnuMenu22,
this.mnuMenu23,
this.mnuMenu24});
this.mnuMenu2.Text = "Menu 2";
//
// mnuMenu21
//
this.mnuMenu21.Index = 0;
this.mnuMenu21.MergeOrder = 1;
this.mnuMenu21.Text = "Menu 2.1";
//
// mnuMenu22
//
this.mnuMenu22.Index = 1;
this.mnuMenu22.MergeOrder = 2;
this.mnuMenu22.MergeType = System.Windows.Forms.MenuMerge.Replace;
this.mnuMenu22.Text = "Menu 2.2";
//
// mnuMenu23
//
this.mnuMenu23.Index = 2;
this.mnuMenu23.MergeOrder = 3;
this.mnuMenu23.MergeType = System.Windows.Forms.MenuMerge.Remove;
this.mnuMenu23.Text = "Menu 2.3";
//
// mnuMenu24
//
this.mnuMenu24.Index = 3;
this.mnuMenu24.MergeOrder = 5;
this.mnuMenu24.Text = "Menu 2.4";
//
// mnuSpecial
//
this.mnuSpecial.Index = 4;
this.mnuSpecial.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuODVote,
this.mnuODShazam});
this.mnuSpecial.Text = "Special";
//
// mnuODVote
//
this.mnuODVote.Index = 0;
this.mnuODVote.OwnerDraw = true;
this.mnuODVote.Text = "Vote";
//
// mnuODShazam
//
this.mnuODShazam.Index = 1;
this.mnuODShazam.OwnerDraw = true;
this.mnuODShazam.Text = "Shazam";
//
// ToolBarLinkedWithMenu
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(440, 126);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "ToolBarLinkedWithMenu";
this.Text = "ToolBarLinkedWithMenu";
}
[STAThread]
static void Main()
{
Application.Run(new ToolBarLinkedWithMenu());
}
private void toolBar1_ButtonClick( object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
ToolBarButton btn = e.Button;
MenuItem mi = (MenuItem) btn.Tag;
mi.PerformClick();
}
}
ToolBar.Buttons.AddRange
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class ToolBarButtonActioin : System.Windows.Forms.Form
{
private ImageList toolBarIcons;
private ToolBarButton tbExitButton;
private ToolBarButton tbSaveButton;
private ToolBar toolBar;
private System.ruponentModel.Container components = null;
public ToolBarButtonActioin()
{
this.ruponents = new System.ruponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
toolBar = new ToolBar();
toolBarIcons = new ImageList();
tbSaveButton = new ToolBarButton();
tbExitButton = new ToolBarButton();
tbSaveButton.ImageIndex = 0;
tbSaveButton.ToolTipText = "Save";
tbExitButton.ImageIndex = 1;
tbExitButton.ToolTipText = "Exit";
toolBar.ImageList = toolBarIcons;
toolBar.Size = new System.Drawing.Size(272, 28);
toolBar.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
toolBar.ShowToolTips = true;
toolBar.Buttons.AddRange(new ToolBarButton[] {tbSaveButton, tbExitButton});
toolBar.ButtonClick += new ToolBarButtonClickEventHandler(ToolBar_Clicked);
toolBarIcons.ImageSize = new System.Drawing.Size(32, 32);
toolBarIcons.Images.Add(new Icon("filesave.ico"));
toolBarIcons.Images.Add(new Icon("fileexit.ico"));
toolBarIcons.ColorDepth = ColorDepth.Depth16Bit;
toolBarIcons.TransparentColor = System.Drawing.Color.Transparent;
this.Controls.Add(toolBar);
}
[STAThread]
static void Main()
{
Application.Run(new ToolBarButtonActioin());
}
private void ToolBar_Clicked(object sender, ToolBarButtonClickEventArgs e)
{
MessageBox.Show(e.Button.ToolTipText);
}
}
ToolBar.Controls.Add
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class ToolBarForm : System.Windows.Forms.Form
{
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton btnNew;
private System.Windows.Forms.ToolBarButton btnOpen;
private System.Windows.Forms.ToolBarButton btnSave;
private System.ruponentModel.IContainer components;
public ToolBarForm()
{
InitializeComponent();
ComboBox cb = new ComboBox();
cb.Left = 150;
cb.Top = 5;
cb.Items.Add("Alabama");
cb.Items.Add("Alaska");
cb.Items.Add("Arizona");
cb.Items.Add("Arkansas");
toolBar1.Controls.Add(cb);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.ruponents = new System.ruponentModel.Container();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.btnNew = new System.Windows.Forms.ToolBarButton();
this.btnOpen = new System.Windows.Forms.ToolBarButton();
this.btnSave = new System.Windows.Forms.ToolBarButton();
this.SuspendLayout();
this.toolBar1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.btnNew,
this.btnOpen,
this.btnSave});
this.toolBar1.DropDownArrows = true;
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(440, 41);
this.toolBar1.TabIndex = 1;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// btnNew
//
this.btnNew.ImageIndex = 0;
this.btnNew.Tag = "New";
this.btnNew.Text = "New";
this.btnNew.ToolTipText = "New Document";
//
// btnOpen
//
this.btnOpen.ImageIndex = 1;
this.btnOpen.Tag = "Open";
this.btnOpen.Text = "Open";
this.btnOpen.ToolTipText = "Open a document";
//
// btnSave
//
this.btnSave.ImageIndex = 3;
this.btnSave.Tag = "Save";
this.btnSave.Text = "Save";
this.btnSave.ToolTipText = "Save document";
//
// ToolBarForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(440, 126);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.toolBar1});
this.IsMdiContainer = true;
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new ToolBarForm());
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch ( e.Button.Tag.ToString() )
{
case "New":
Console.WriteLine("New");
break;
case "Open":
Console.WriteLine("Open");
break;
case "Save":
Console.WriteLine("Save");
break;
}
}
}
ToolBar.ImageList
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class ToolBarToolTip : System.Windows.Forms.Form
{
private ImageList toolBarIcons;
private ToolBarButton tbExitButton;
private ToolBarButton tbSaveButton;
private ToolBar toolBar;
private System.ruponentModel.Container components = null;
public ToolBarToolTip()
{
this.ruponents = new System.ruponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
toolBar = new ToolBar();
toolBarIcons = new ImageList();
tbSaveButton = new ToolBarButton();
tbExitButton = new ToolBarButton();
tbSaveButton.ImageIndex = 0;
tbSaveButton.ToolTipText = "Save";
tbExitButton.ImageIndex = 1;
tbExitButton.ToolTipText = "Exit";
toolBar.ImageList = toolBarIcons;
toolBar.Size = new System.Drawing.Size(272, 28);
toolBar.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
toolBar.ShowToolTips = true;
toolBar.Buttons.AddRange(new ToolBarButton[] {tbSaveButton, tbExitButton});
toolBar.ButtonClick += new ToolBarButtonClickEventHandler(ToolBar_Clicked);
toolBarIcons.ImageSize = new System.Drawing.Size(32, 32);
toolBarIcons.Images.Add(new Icon("filesave.ico"));
toolBarIcons.Images.Add(new Icon("fileexit.ico"));
toolBarIcons.ColorDepth = ColorDepth.Depth16Bit;
toolBarIcons.TransparentColor = System.Drawing.Color.Transparent;
this.Controls.Add(toolBar);
}
[STAThread]
static void Main()
{
Application.Run(new ToolBarToolTip());
}
private void ToolBar_Clicked(object sender, ToolBarButtonClickEventArgs e)
{
MessageBox.Show(e.Button.ToolTipText);
}
}
ToolBar.ShowToolTips
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class ImageListCreateAndAddToToolBar : System.Windows.Forms.Form
{
private ImageList toolBarIcons;
private ToolBarButton tbExitButton;
private ToolBarButton tbSaveButton;
private ToolBar toolBar;
private System.ruponentModel.Container components = null;
public ImageListCreateAndAddToToolBar()
{
this.ruponents = new System.ruponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
toolBar = new ToolBar();
toolBarIcons = new ImageList();
tbSaveButton = new ToolBarButton();
tbExitButton = new ToolBarButton();
tbSaveButton.ImageIndex = 0;
tbExitButton.ImageIndex = 1;
toolBar.ImageList = toolBarIcons;
toolBar.Size = new System.Drawing.Size(272, 28);
toolBar.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
toolBar.ShowToolTips = true;
toolBar.Buttons.AddRange(new ToolBarButton[] {tbSaveButton, tbExitButton});
toolBar.ButtonClick += new ToolBarButtonClickEventHandler(ToolBar_Clicked);
toolBarIcons.ImageSize = new System.Drawing.Size(32, 32);
toolBarIcons.Images.Add(new Icon("filesave.ico"));
toolBarIcons.Images.Add(new Icon("fileexit.ico"));
toolBarIcons.ColorDepth = ColorDepth.Depth16Bit;
toolBarIcons.TransparentColor = System.Drawing.Color.Transparent;
this.Controls.Add(toolBar);
}
[STAThread]
static void Main()
{
Application.Run(new ImageListCreateAndAddToToolBar());
}
private void ToolBar_Clicked(object sender, ToolBarButtonClickEventArgs e)
{
MessageBox.Show(e.Button.ToolTipText);
}
}