Toolbar Styles : Toolbar « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » Toolbar 
23.38.12.Toolbar Styles
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

  public class ToolbarStylesForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.ToolBar tbMain;
    private System.Windows.Forms.MainMenu mainMenu1;
    private System.Windows.Forms.MenuItem menuItem1;
    private System.Windows.Forms.MenuItem mnuAppearanceNormal;
    private System.Windows.Forms.MenuItem mnuAppearanceFlat;
    private System.Windows.Forms.MenuItem mnuTextAlignUnderneath;
    private System.Windows.Forms.MenuItem mnuTextAlignRight;
    private System.Windows.Forms.MenuItem mnuDivider;
    string[] astrTBarButtons = "New""Open""Save",
                     "Cut""Copy""Paste""Print""Help"};

    public ToolbarStylesForm()
    {
      InitializeComponent();

      tbMain.ImageList = new ImageList();
      Bitmap bmpImageStrip = new Bitmap(GetType()"Toolbar.bmp");
      bmpImageStrip.MakeTransparent(Color.FromArgb(0xff0x000xff));
      tbMain.ImageList.ImageSize = new Size(1615);
      tbMain.ImageList.Images.AddStrip(bmpImageStrip);
      
      // Create the toolbar buttons
      for (int i=0; i < astrTBarButtons.Length; i++)
      {
        ToolBarButton tbb = new ToolBarButton();
        tbb.ImageIndex = i;
        tbb.ToolTipText = astrTBarButtons[i];
        tbMain.Buttons.Add(tbb);
      }
    }

    private void InitializeComponent()
    {
      this.tbMain = new System.Windows.Forms.ToolBar();
      this.mainMenu1 = new System.Windows.Forms.MainMenu();
      this.menuItem1 = new System.Windows.Forms.MenuItem();
      this.mnuAppearanceNormal = new System.Windows.Forms.MenuItem();
      this.mnuAppearanceFlat = new System.Windows.Forms.MenuItem();
      this.mnuTextAlignUnderneath = new System.Windows.Forms.MenuItem();
      this.mnuTextAlignRight = new System.Windows.Forms.MenuItem();
      this.mnuDivider = new System.Windows.Forms.MenuItem();
      this.SuspendLayout();
      // 
      // tbMain
      // 
      this.tbMain.DropDownArrows = true;
      this.tbMain.Name = "tbMain";
      this.tbMain.ShowToolTips = true;
      this.tbMain.Size = new System.Drawing.Size(29239);
      this.tbMain.TabIndex = 0;
      // 
      // mainMenu1
      // 
      this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                            this.menuItem1});
      // 
      // menuItem1
      // 
      this.menuItem1.Index = 0;
      this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                            this.mnuAppearanceNormal,
                                            this.mnuAppearanceFlat,
                                            this.mnuDivider,
                                            this.mnuTextAlignUnderneath,
                                            this.mnuTextAlignRight});
      this.menuItem1.Text = "Styles";
      // 
      // mnuAppearanceNormal
      // 
      this.mnuAppearanceNormal.Index = 0;
      this.mnuAppearanceNormal.Text = "Normal";
      this.mnuAppearanceNormal.Click += new System.EventHandler(this.OnAppearanceNormal);
      // 
      // mnuAppearanceFlat
      // 
      this.mnuAppearanceFlat.Index = 1;
      this.mnuAppearanceFlat.Text = "Flat";
      this.mnuAppearanceFlat.Click += new System.EventHandler(this.OnAppearanceFlat);
      // 
      // mnuTextAlignUnderneath
      // 
      this.mnuTextAlignUnderneath.Index = 3;
      this.mnuTextAlignUnderneath.Text = "Text underneath";
      this.mnuTextAlignUnderneath.Click += new System.EventHandler(this.OnTextAlignUnderneath);
      // 
      // mnuTextAlignRight
      // 
      this.mnuTextAlignRight.Index = 4;
      this.mnuTextAlignRight.Text = "Text right";
      this.mnuTextAlignRight.Click += new System.EventHandler(this.OnTextAlignRight);
      // 
      // mnuDivider
      // 
      this.mnuDivider.Index = 2;
      this.mnuDivider.Text = "Divider";
      this.mnuDivider.Click += new System.EventHandler(this.OnDivider);
      // 
      // ToolbarStylesForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292273);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.tbMain});
      this.Menu = this.mainMenu1;
      this.Name = "ToolbarStylesForm";
      this.Text = "Toolbar Styles";
      this.ResumeLayout(false);

    }
    static void Main() 
    {
      Application.Run(new ToolbarStylesForm());
    }

    private void OnAppearanceNormal(object sender, System.EventArgs e)
    {
      tbMain.Appearance = ToolBarAppearance.Normal;
    }

    private void OnAppearanceFlat(object sender, System.EventArgs e)
    {
      tbMain.Appearance = ToolBarAppearance.Flat;
    }

    private void OnDivider(object sender, System.EventArgs e)
    {
      tbMain.Divider = !tbMain.Divider;
    }

    private void OnTextAlignUnderneath(object sender, System.EventArgs e)
    {
      AddTextToToolBarButtons();
      tbMain.TextAlign = ToolBarTextAlign.Underneath;
    }

    private void OnTextAlignRight(object sender, System.EventArgs e)
    {
      AddTextToToolBarButtons();
      tbMain.TextAlign = ToolBarTextAlign.Right;
    }

    private void AddTextToToolBarButtons()
    {
      for (int i=0; i < astrTBarButtons.Length; i++)
      {
        tbMain.Buttons[i].Text = astrTBarButtons[i];
      }
    }

    private void RemoveTextFromToolBarButtons()
    {
      for (int i=0; i < astrTBarButtons.Length; i++)
      {
        tbMain.Buttons[i].Text = "";
      }
      tbMain.Refresh();
    }
  }
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.