Form.MenuComplete : Form « 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 » Form 
Form.MenuComplete
  
   using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;
  
  internal struct TheFontSize
  {
    public static int Huge = 30;
    public static int Normal = 20;
    public static int Tiny = 8;
  }
  
  public class mainForm : System.Windows.Forms.Form
  {
    Color currColor = Color.MistyRose;
    private int currFontSize = TheFontSize.Normal;
    private StatusBarPanel sbPnlPrompt = new StatusBarPanel();
    private StatusBarPanel sbPnlTime = new StatusBarPanel();
    private MainMenu mainMenu = new MainMenu();
    
    private MenuItem currentCheckedItem;
    private MenuItem checkedHuge;
    private MenuItem checkedNormal;
    private MenuItem checkedTiny;


    public mainForm()
    {
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292273);

      this.MenuComplete += new EventHandler(StatusForm_MenuDone);

      BuildMenuSystem();
      BuildStatBar();
    }

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

    private void FileExit_Clicked(object sender, EventArgs e
    {
      Console.WriteLine("File | Exit Menu item handler");
      this.Close();
    }

    private void FileSave_Clicked(object sender, EventArgs e
    {
            Console.WriteLine("File | Save Menu item handler");
    }

    private void ColorItem_Clicked(object sender, EventArgs e
    {
      MenuItem miClicked = (MenuItem)sender;
      string color = miClicked.Text.Remove(0,1);
      
      this.BackColor = Color.FromName(color);
      currColor = this.BackColor;
    }

    private void PopUp_Clicked(object sender, EventArgs e
    {
      currentCheckedItem.Checked = false;

      MenuItem miClicked = (MenuItem)sender;
      string item = miClicked.Text;
      
      if(item == "Huge") {
        currFontSize = TheFontSize.Huge;
        currentCheckedItem = checkedHuge;
      }else if(item == "Normal") {
        currFontSize = TheFontSize.Normal;
        currentCheckedItem = checkedNormal;
      }else if(item == "Tiny") {
        currFontSize = TheFontSize.Tiny;
        currentCheckedItem = checkedTiny;
      }
      currentCheckedItem.Checked = true;
      Invalidate();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
      Graphics g = e.Graphics;

      g.DrawString("www.java2java.com"
        new Font("Times New Roman"(float)currFontSize)
        new SolidBrush(Color.Black)
        this.DisplayRectangle);
    }
    
    protected override void OnResize(EventArgs e)
    {
      base.OnResize(e);
      Invalidate();
    }

    private void HelpAbout_Clicked(object sender, EventArgs e
    {
      Console.WriteLine("The amazing final app...""About...");
    }
        
    private void FileMenuItem_Selected(object sender, EventArgs e
    {
      MenuItem miClicked = (MenuItem)sender;
      string item = miClicked.Text.Remove(0,1);
      
      if(item == "Save..."){
        sbPnlPrompt.Text = "Save current settings.";     
      }else{
        sbPnlPrompt.Text = "Terminates this app.";     
        
    }

    private void ColorMenuItem_Selected(object sender, EventArgs e
    {
      MenuItem miClicked = (MenuItem)sender;
      string item = miClicked.Text.Remove(0,1);
      sbPnlPrompt.Text = "Select " + item;            
    }

    private void HelpAbout_Selected(object sender, EventArgs e
    {
      sbPnlPrompt.Text = "Displays app info";
    }

    private void StatusForm_MenuDone(object sender, EventArgs e
    {
      sbPnlPrompt.Text = "Ready";
    }

    private void timer1_Tick(object sender, EventArgs e
    {
      DateTime t = DateTime.Now;
      string s = t.ToLongTimeString() ;
      sbPnlTime.Text = s ;    
    }

    private void BuildMenuSystem()
    {
      MenuItem miFile = mainMenu.MenuItems.Add("&File");           
      miFile.MenuItems.Add(new MenuItem("&Save..."new EventHandler(this.FileSave_Clicked), Shortcut.CtrlS));     
      miFile.MenuItems.Add(new MenuItem("E&xit"new EventHandler(this.FileExit_Clicked), Shortcut.CtrlX));

      miFile.MenuItems[0].Select += new EventHandler(FileMenuItem_Selected);
      miFile.MenuItems[1].Select += new EventHandler(FileMenuItem_Selected);

      MenuItem miColor = mainMenu.MenuItems.Add("&Background Color");
      miColor.MenuItems.Add("&DarkGoldenrod"new EventHandler(ColorItem_Clicked));
      miColor.MenuItems.Add("&GreenYellow"new EventHandler(ColorItem_Clicked));
      
      for(int i = 0; i < miColor.MenuItems.Count; i++){
        miColor.MenuItems[i].Select += new EventHandler(ColorMenuItem_Selected);
            }

      MenuItem miHelp = mainMenu.MenuItems.Add("Help");  
      miHelp.MenuItems.Add(new MenuItem("&amp;About"new EventHandler(this.HelpAbout_Clicked), Shortcut.CtrlA));
      miHelp.MenuItems[0].Select += new EventHandler(HelpAbout_Selected);

      this.Menu = mainMenu;  

            ContextMenu popUpMenu = new ContextMenu();

      popUpMenu.MenuItems.Add("Huge"new EventHandler(PopUp_Clicked));
      popUpMenu.MenuItems.Add("Normal"new EventHandler(PopUp_Clicked));
      popUpMenu.MenuItems.Add("Tiny"new EventHandler(PopUp_Clicked));

      this.ContextMenu = popUpMenu;

      checkedHuge = this.ContextMenu.MenuItems[0];
      checkedNormal = this.ContextMenu.MenuItems[1];        
      checkedTiny = this.ContextMenu.MenuItems[2];
      
      if(currFontSize == TheFontSize.Huge)
        currentCheckedItem = checkedHuge;
      else if(currFontSize == TheFontSize.Normal)
        currentCheckedItem = checkedNormal;
      else
        currentCheckedItem = checkedTiny;

      currentCheckedItem.Checked = true;
    }

    private void BuildStatBar()
    {
        Timer timer1 = new Timer();
      timer1.Interval = 1000;
      timer1.Enabled = true;
      timer1.Tick += new EventHandler(timer1_Tick);

        StatusBar statusBar = new StatusBar();
        
      statusBar.ShowPanels = true;
      statusBar.Panels.AddRange((StatusBarPanel[])new StatusBarPanel[] {sbPnlPrompt, sbPnlTime});

      sbPnlPrompt.BorderStyle = StatusBarPanelBorderStyle.None;
      sbPnlPrompt.AutoSize = StatusBarPanelAutoSize.Spring;
      sbPnlPrompt.Width = 62;
      sbPnlPrompt.Text = "Ready";

      sbPnlTime.Alignment = System.Windows.Forms.HorizontalAlignment.Right;
      sbPnlTime.Width = 76;

      try
      {
        Icon i = new Icon("icon1.ico");
        sbPnlPrompt.Icon = i;
      catch(Exception e) {
        MessageBox.Show(e.Message);
      }

      this.Controls.Add(statusBar);  
    }

  }

   
    
  
Related examples in the same category
1.new Form()
2.extends Form
3.Form.AcceptButton
4.Form.ActiveForm.Location
5.Form.Activated
6.Form.AddOwnedForm
7.Form.AutoScaleBaseSize
8.Form.AutoScroll
9.Form.AutoScrollMinSize
10.Form.BackColor
11.Form.CancelButton
12.Form.CenterToScreen()
13.Form.ClientRectangle
14.Form.ClientSize
15.Form.Closed
16.Form.Closing
17.Form.ContextMenu
18.Form.ControlBox
19.Form.Controls
20.Form.Cursor
21.Form.DesktopBounds
22.Form.DialogResult
23.Form.DisplayRectangle
24.Form.Dispose
25.Form.FormBorderStyle
26.Form.ForeColor
27.Form.GotFocus
28.Form.Height
29.Form.Hide()
30.Form.Invalidate
31.Form.IsMdiContainer
32.Form.KeyPress
33.Form.KeyPreview
34.Form.KeyUp
35.Form.Load
36.Form.Location
37.Form.MaximizeBox
38.Form.MaximumSize
39.Form.MdiParent
40.Form.Menu
41.Form.MinimizeBox
42.Form.MinimumSize
43.Form.MouseDown
44.Form.MouseLeave(All other events)
45.Form.MouseUp
46.Form.OnDragDrop
47.Form.OnDragOver
48.Form.OnInputLanguageChanged
49.Form.OnKeyDown
50.Form.OnKeyPress
51.Form.OnMouseEnter
52.Form.OnMouseHover
53.Form.OnMouseLeave
54.Form.OnMouseMove
55.Form.OnMouseWheel
56.Form.OnPaint(PaintEventArgs e)
57.Form.OnResize
58.Form.Opacity
59.Form.Paint
60.Form.Region
61.Form.Resize
62.Form.ResizeRedraw
63.Form.SetStyle
64.Form.ShowInTaskbar
65.Form.Size
66.Form.Show
67.Form.StartPosition
68.Form.SuspendLayout
69.Form.Text
70.Form.Top
71.Form.TransparencyKey
72.Form.Visible
73.Form.Width
74.Form.WindowState
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.