new ToolBarButton : ToolBarButton « System.Windows.Forms « C# / C Sharp by API

Home
C# / C Sharp by API
1.Microsoft.Win32
2.System
3.System.Collections
4.System.Collections.Generic
5.System.Collections.Specialized
6.System.ComponentModel
7.System.Configuration
8.System.Data
9.System.Data.Common
10.System.Data.Linq
11.System.Data.Odbc
12.System.Data.OleDb
13.System.Data.Sql
14.System.Data.SqlClient
15.System.Diagnostics
16.System.DirectoryServices
17.System.Drawing
18.System.Drawing.Drawing2D
19.System.Drawing.Imaging
20.System.Drawing.Printing
21.System.Drawing.Text
22.System.EnterpriseServices
23.System.Globalization
24.System.IO
25.System.IO.Compression
26.System.IO.IsolatedStorage
27.System.IO.Ports
28.System.Linq
29.System.Management
30.System.Media
31.System.Messaging
32.System.Net
33.System.Net.Mail
34.System.Net.NetworkInformation
35.System.Net.Sockets
36.System.Reflection
37.System.Resources
38.System.Runtime
39.System.Runtime.CompilerServices
40.System.Runtime.InteropServices
41.System.Runtime.Remoting
42.System.Runtime.Remoting.Channels
43.System.Runtime.Remoting.Channels.Http
44.System.Runtime.Remoting.Messaging
45.System.Runtime.Serialization
46.System.Runtime.Serialization.Formatters.Binary
47.System.Runtime.Serialization.Formatters.Soap
48.System.Security
49.System.Security.AccessControl
50.System.Security.Cryptography
51.System.Security.Cryptography.X509Certificates
52.System.Security.Permissions
53.System.Security.Policy
54.System.Security.Principal
55.System.ServiceProcess
56.System.Text
57.System.Text.RegularExpressions
58.System.Threading
59.System.Timers
60.System.Web.Security
61.System.Web.Services
62.System.Windows.Controls
63.System.Windows.Forms
64.System.Xml
65.System.Xml.Linq
66.System.Xml.Schema
67.System.Xml.Serialization
68.System.Xml.XPath
69.System.Xml.Xsl
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp by API » System.Windows.Forms » ToolBarButton 
new ToolBarButton
 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class ToolBarButtonAction : System.Windows.Forms.Form
{
  private System.Windows.Forms.ToolBar toolBar1;
  private System.Windows.Forms.ToolBarButton toolBarButton1;
  private System.Windows.Forms.ToolBarButton toolBarButton2;
  private System.Windows.Forms.ToolBarButton toolBarButton3;
  private System.Windows.Forms.ImageList imageList1;
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.MenuItem Open;
  private System.Windows.Forms.MenuItem Test;
  private System.Windows.Forms.MenuItem Exit;
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.Button button2;
  private System.Windows.Forms.Button button3;
  private System.Windows.Forms.TextBox textBox1;
  private System.ComponentModel.IContainer components;

  public ToolBarButtonAction()
  {
    InitializeComponent();
  }
  protected override void Disposebool disposing )
  {
    ifdisposing )
    {
      if (components != null
      {
        components.Dispose();
      }
    }
    base.Disposedisposing );
  }

  private void InitializeComponent()
  {
    this.components = new System.ComponentModel.Container();
    this.toolBar1 = new System.Windows.Forms.ToolBar();
    this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
    this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
    this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    this.menuItem1 = new System.Windows.Forms.MenuItem();
    this.Open = new System.Windows.Forms.MenuItem();
    this.Test = new System.Windows.Forms.MenuItem();
    this.Exit = new System.Windows.Forms.MenuItem();
    this.button1 = new System.Windows.Forms.Button();
    this.button2 = new System.Windows.Forms.Button();
    this.button3 = new System.Windows.Forms.Button();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    // 
    // 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(29239);
    this.toolBar1.TabIndex = 0;
    this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
    // 
    // toolBarButton1
    // 
    this.toolBarButton1.ImageIndex = 0;
    this.toolBarButton1.Text = "Open";
    this.toolBarButton1.ToolTipText = "Opens a file";
    // 
    // toolBarButton2
    // 
    this.toolBarButton2.ImageIndex = 1;
    this.toolBarButton2.Text = "Test";
    this.toolBarButton2.ToolTipText = "Test";
    // 
    // toolBarButton3
    // 
    this.toolBarButton3.ImageIndex = 2;
    this.toolBarButton3.Text = "Exit";
    this.toolBarButton3.ToolTipText = "Close Program";

    // 
    // 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.Open,
                                          this.Test,
                                          this.Exit});
    this.menuItem1.Text = "Main Menu Options";
    // 
    // Open
    // 
    this.Open.Index = 0;
    this.Open.Text = "Open";
    this.Open.Click += new System.EventHandler(this.OpenMenuItemClick);
    // 
    // Test
    // 
    this.Test.Index = 1;
    this.Test.Text = "Test";
    this.Test.Click += new System.EventHandler(this.TestMenuItemClick);
    // 
    // Exit
    // 
    this.Exit.Index = 2;
    this.Exit.Text = "Exit";
    this.Exit.Click += new System.EventHandler(this.ExitMenuItemClick);
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(864);
    this.button1.Name = "button1";
    this.button1.Size = new System.Drawing.Size(12832);
    this.button1.TabIndex = 1;
    this.button1.Text = "Open File Dialog";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // button2
    // 
    this.button2.Location = new System.Drawing.Point(16072);
    this.button2.Name = "button2";
    this.button2.Size = new System.Drawing.Size(12032);
    this.button2.TabIndex = 2;
    this.button2.Text = "FontDialog";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // button3
    // 
    this.button3.Location = new System.Drawing.Point(40120);
    this.button3.Name = "button3";
    this.button3.Size = new System.Drawing.Size(13632);
    this.button3.TabIndex = 3;
    this.button3.Text = "ColorDialog";
    this.button3.Click += new System.EventHandler(this.button3_Click);
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(88184);
    this.textBox1.Name = "textBox1";
    this.textBox1.Size = new System.Drawing.Size(16820);
    this.textBox1.TabIndex = 4;
    this.textBox1.Text = "textBox1";
    // 
    // ToolBarButtonAction
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(513);
    this.ClientSize = new System.Drawing.Size(292266);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                    this.textBox1,
                                    this.button3,
                                    this.button2,
                                    this.button1,
                                    this.toolBar1});
    this.Menu = this.mainMenu1;
    this.Name = "ToolBarButtonAction";
    this.Text = "ToolBarButtonAction";
    this.Load += new System.EventHandler(this.ToolBarButtonAction_Load);
    this.ResumeLayout(false);

  }

  [STAThread]
  static void Main() 
  {
    Application.Run(new ToolBarButtonAction());
  }

  private void ToolBarButtonAction_Load(object sender, System.EventArgs e)
  {
  
  }

  private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
  {
    if e.Button == toolBarButton1 )
    {
      MessageBox.Show"Open Button Clicked ");
    }
    if e.Button == toolBarButton2 )
    {
      MessageBox.Show"Test Button Clicked ");
    }
    if e.Button == toolBarButton3 )
    {
      MessageBox.Show"Exit Button Clicked ");
    

  }

  private void TestMenuItemClick(object sender, System.EventArgs e)
  {
    MessageBox.Show"Test Menu ItemClicked ");
  }

  private void OpenMenuItemClick(object sender, System.EventArgs e)
  {
    MessageBox.Show"Open Menu ItemClicked ");
  }

  private void ExitMenuItemClick(object sender, System.EventArgs e)
  {
    MessageBox.Show"Exit Menu ItemClicked ");
  }

  private void button1_Click(object sender, System.EventArgs e)
  {
    OpenFileDialog fdlg = new OpenFileDialog()
    fdlg.Title = "C# Corner Open File Dialog" 
    fdlg.InitialDirectory = @"c:\" ; 
    fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" ; 
    fdlg.FilterIndex = 2 ; 
    fdlg.RestoreDirectory = true ; 
    if(fdlg.ShowDialog() == DialogResult.OK) 
    
      textBox1.Text = fdlg.FileName ; 
    }
  }

  private void button2_Click(object sender, System.EventArgs e)
  {
    FontDialog fntDlg = new FontDialog(); 
    fntDlg.ShowColor = true; 
    if(fntDlg.ShowDialog() != DialogResult.Cancel ) 
    
      textBox1.Font = fntDlg.Font ; 
      textBox1.ForeColor = fntDlg.Color; 
    }
  }

  private void button3_Click(object sender, System.EventArgs e)
  {
    ColorDialog colorDlg = new ColorDialog();
    colorDlg.ShowDialog();
    textBox1.BackColor = colorDlg.Color;
    button1.BackColor = colorDlg.Color;
    button3.BackColor = colorDlg.Color;

  }
}

   
  
Related examples in the same category
1.new ToolBarButtonClickEventHandler
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.