Toolbar with ComboBox : Toolbar « GUI Windows Forms « C# / CSharp Tutorial






Toolbar with ComboBox
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
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.ComponentModel.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.components = new System.ComponentModel.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;
    }

  }
}








23.38.Toolbar
23.38.1.Toolbar with ComboBoxToolbar with ComboBox
23.38.2.ToolBar Linked With MenuToolBar Linked With Menu
23.38.3.ToolBar Button ActionToolBar Button Action
23.38.4.Add Button action to ToolBar ButtonAdd Button action to ToolBar Button
23.38.5.Add ToolTip to ToolBar ButtonAdd ToolTip to ToolBar Button
23.38.6.Create an ImageList and use it for ToolBarCreate an ImageList and use it for ToolBar
23.38.7.Add Image to ToolBar ButtonAdd Image to ToolBar Button
23.38.8.ToolBar Button border style: BorderStyle.Fixed3DToolBar Button border style: BorderStyle.Fixed3D
23.38.9.Cut, Copy Paste/Text Box with Toolbar
23.38.10.Designed Toolbar
23.38.11.ToolBar Button Style
23.38.12.Toolbar Styles