Using ToolBarButton : ToolBar « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » ToolBarScreenshots 
Using ToolBarButton
 


using System;
using System.Drawing;
using System.Windows.Forms;
   
class ToggleButtons: Form
{
     protected Panel   panel = new Panel();
     protected ToolBar tbar;
     protected string  strText = "Toggle";
     protected Color   clrText = SystemColors.WindowText;
     FontStyle         fontstyle = FontStyle.Regular;
   
     public static void Main()
     {
          Application.Run(new ToggleButtons());
     }
     public ToggleButtons()
     {
          panel.Parent = this;
          panel.Dock = DockStyle.Fill;
          panel.BackColor = SystemColors.Window;
          panel.ForeColor = SystemColors.WindowText;
          panel.Resize += new EventHandler(PanelOnResize);
          panel.Paint += new PaintEventHandler(PanelOnPaint);
   
          Bitmap bm = new Bitmap(GetType()"ToggleButtons.bmp");
   
          ImageList imglst = new ImageList();
          imglst.ImageSize = new Size(bm.Width / 4, bm.Height);
          imglst.Images.AddStrip(bm);
          imglst.TransparentColor = Color.White;
   
          tbar = new ToolBar();
          tbar.ImageList = imglst;
          tbar.Parent = this;
          tbar.ShowToolTips = true;
          tbar.ButtonClick += new ToolBarButtonClickEventHandler(ToolBarOnClick);
   
          FontStyle[] afs = FontStyle.Bold, FontStyle.Italic,
                              FontStyle.Underline, FontStyle.Strikeout };
   
          for (int i = 0; i < 4; i++)
          {
               ToolBarButton tbarbtn = new ToolBarButton();
               tbarbtn.ImageIndex = i;
               tbarbtn.Style = ToolBarButtonStyle.ToggleButton;
               tbarbtn.ToolTipText = afs[i].ToString();
               tbarbtn.Tag = afs[i];
   
               tbar.Buttons.Add(tbarbtn);
          }
     }
     void ToolBarOnClick(object obj, ToolBarButtonClickEventArgs tbbcea)
     {
          ToolBarButton tbarbtn = tbbcea.Button;
   
          if (tbarbtn.Tag == null ||
              tbarbtn.Tag.GetType() != typeof(FontStyle))
               return;
   
          if (tbarbtn.Pushed)
               fontstyle |= (FontStyletbarbtn.Tag;
          else
               fontstyle &= ~(FontStyletbarbtn.Tag;
   
          panel.Invalidate();
     }
     void PanelOnResize(object obj, EventArgs ea)
     {
          Panel panel = (Panelobj;
          panel.Invalidate();
     }
     void PanelOnPaint(object obj, PaintEventArgs pea)
     {
          Panel    panel = (Panelobj;
          Graphics grfx  = pea.Graphics;
          Font     font  = new Font("Times New Roman"72, fontstyle);
          SizeF    sizef = grfx.MeasureString(strText, font);
   
          grfx.DrawString(strText, font, new SolidBrush(clrText),
                          (panel.Width - sizef.Width2,
                          (panel.Height - sizef.Height2);
     }
}

 
Related examples in the same category
1.ImageList for ToolBar
2.ToolBar float windowToolBar float window
3.ToolBar Example
4.Floating ToolbarFloating Toolbar
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.