делать красивыми, вынося на них рисунки, ассоциированные с командами. Поэтому посадим на форму два элемента управления - ImageList, хранящий рисунки, связываемые с кнопками, и ToolBar - панель, на которой будут располагаться кнопки. В коллекцию объекта imageList1 добавим три подходящие картинки, свяжем этот объект со свойством ImageList объекта toolBar1. Затем добавим три кнопки в коллекцию объекта toolBar1 и зададим для них нужные свойства - текст, появляющийся на кнопке, подсказку к кнопке и индекс элемента из списка ImageList. На рис. 24.11 показан процесс задания кнопки и установки ее свойств.
Рис. 24.11. Проектирование панели с командными кнопками Проанализируем теперь созданный дизайнером программный код. Как всегда начнем с полей класса, хранящих созданные в процессе проектирования элементы: private System.Windows.Forms.ToolBar toolBar1; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.ToolBarButton toolBarButton1; private System.Windows.Forms.ToolBarButton toolBarButton2; private System.Windows.Forms.ToolBarButton toolBarButton3; В методе InitializeComponent эти объекты создаются и инициализируются: 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.toolBar1.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.TabIndex = 1; this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler( this.toolBar1_ButtonClick); // toolBarButton1 this.toolBarButton1.ImageIndex = 0; this.toolBarButton1.Text = "OpenFile"; this.toolBarButton1.ToolTipText = "Диалоговое окно открытия файла"; ... Этот текст должен быть понятен без комментариев, а вот об обработчике события Click стоит сказать несколько слов. Во-первых, событие |