Роль контейнерного класса для командных кнопок играет класс, определяющий панель —
Давайте спроектируем панель с тремя кнопками, задающими команды
Рис. 24.11.
Проанализируем теперь созданный дизайнером программный код. Как всегда начнем с полей класса, хранящих созданные в процессе проектирования элементы:
private System.Windows.Forms.ToolBar tooiBar1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
В методе
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
…
// toolBar1
this.toolBari.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[]
{this.toolBarButton1, this.toolBarButton2,this.toolBarButton3});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(432, 42);
this.toolBar1.Tablndex = 1;
this.toolBar1.ButtonClick +=
new System.Windows.Forms.ToolBarButtonClickEventHandler
this.toolBar1_ButtonClick);
// toolBarButton1
this.toolBarButton1.Imagelndex = 0;
this.toolBarButton1.Text = "OpenFile";
this.toolBarButton1.ToolTipText =
"Диалоговое окно открытия файла";
…
Этот текст должен быть понятен без комментариев, а вот об обработчике события