MenuItem.Parent : MenuItem « 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 » MenuItem 
MenuItem.Parent
 
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class MenuItemEventOption : System.Windows.Forms.Form
{
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem mnuNew;
  private System.Windows.Forms.MenuItem mnuFile;
  private System.Windows.Forms.MenuItem mnuFileOpen;
  private System.Windows.Forms.MenuItem mnuFileClose;
  private System.Windows.Forms.MenuItem mnuFileSave;
  private System.Windows.Forms.MenuItem mnuFileSaveAs;
  private System.Windows.Forms.MenuItem mnuEdit;
  private System.Windows.Forms.MenuItem mnuEditCopy;
  private System.Windows.Forms.MenuItem mnuEditPaste;
  private System.Windows.Forms.MenuItem mnuOption1;
  private System.Windows.Forms.MenuItem mnuOption2;
  private System.Windows.Forms.MenuItem mnuOption3;
  private System.Windows.Forms.MenuItem mnuROption1;
  private System.Windows.Forms.MenuItem mnuROption2;
  private System.Windows.Forms.MenuItem mnuROption3;
  private System.Windows.Forms.MenuItem mnuWindow;
  private System.Windows.Forms.MenuItem mnuOptions;
  private System.Windows.Forms.MenuItem mnuRadioOptions;

  private System.ComponentModel.Container components = null;

  public MenuItemEventOption()
  {
    InitializeComponent();
  }

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

  private void InitializeComponent()
  {
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    this.mnuFile = new System.Windows.Forms.MenuItem();
    this.mnuNew = new System.Windows.Forms.MenuItem();
    this.mnuFileOpen = new System.Windows.Forms.MenuItem();
    this.mnuFileClose = new System.Windows.Forms.MenuItem();
    this.mnuFileSave = new System.Windows.Forms.MenuItem();
    this.mnuFileSaveAs = new System.Windows.Forms.MenuItem();
    this.mnuEdit = new System.Windows.Forms.MenuItem();
    this.mnuEditCopy = new System.Windows.Forms.MenuItem();
    this.mnuEditPaste = new System.Windows.Forms.MenuItem();
    this.mnuOptions = new System.Windows.Forms.MenuItem();
    this.mnuOption1 = new System.Windows.Forms.MenuItem();
    this.mnuOption2 = new System.Windows.Forms.MenuItem();
    this.mnuOption3 = new System.Windows.Forms.MenuItem();
    this.mnuRadioOptions = new System.Windows.Forms.MenuItem();
    this.mnuROption1 = new System.Windows.Forms.MenuItem();
    this.mnuROption2 = new System.Windows.Forms.MenuItem();
    this.mnuROption3 = new System.Windows.Forms.MenuItem();
    this.mnuWindow = new System.Windows.Forms.MenuItem();

    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
      this.mnuFile, this.mnuEdit, this.mnuOptions, this.mnuRadioOptions, this.mnuWindow});

    this.mnuFile.Index = 0;
    this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                        this.mnuNew,
                                        this.mnuFileOpen,
                                        this.mnuFileClose,
                                        this.mnuFileSave,
                                        this.mnuFileSaveAs});
    this.mnuFile.Text = "File";

    this.mnuNew.Index = 0;
    this.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
    this.mnuNew.Text = "&New";
    this.mnuNew.Click += new System.EventHandler(this.mnuNew_Click);

    this.mnuFileOpen.Index = 1;
    this.mnuFileOpen.Text = "Open";
    this.mnuFileOpen.Click += new System.EventHandler(this.mnuFileOpen_Click);
    // 
    // mnuFileClose
    // 
    this.mnuFileClose.Index = 2;
    this.mnuFileClose.Text = "Close";
    this.mnuFileClose.Click += new System.EventHandler(this.mnuFileClose_Click);
    // 
    // mnuFileSave
    // 
    this.mnuFileSave.Index = 3;
    this.mnuFileSave.Text = "Save";
    this.mnuFileSave.Click += new System.EventHandler(this.mnuFileSave_Click);
    // 
    // mnuFileSaveAs
    // 
    this.mnuFileSaveAs.Index = 4;
    this.mnuFileSaveAs.Text = "Save&As";
    this.mnuFileSaveAs.Click += new System.EventHandler(this.mnuFileSaveAs_Click);
    // 
    // mnuEdit
    // 
    this.mnuEdit.Index = 1;
    this.mnuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                        this.mnuEditCopy,
                                        this.mnuEditPaste});
    this.mnuEdit.Text = "Edit";
    // 
    // mnuEditCopy
    // 
    this.mnuEditCopy.Index = 0;
    this.mnuEditCopy.Text = "&Copy";
    this.mnuEditCopy.Click += new System.EventHandler(this.mnuEditCopy_Click);
    // 
    // mnuEditPaste
    // 
    this.mnuEditPaste.Index = 1;
    this.mnuEditPaste.Text = "Paste";
    this.mnuEditPaste.Click += new System.EventHandler(this.mnuEditPaste_Click);
    // 
    // mnuOptions
    // 
    this.mnuOptions.Index = 2;
    this.mnuOptions.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                           this.mnuOption1,
                                           this.mnuOption2,
                                           this.mnuOption3});
    this.mnuOptions.Text = "Options";
    // 
    // mnuOption1
    // 
    this.mnuOption1.Index = 0;
    this.mnuOption1.Text = "Option1";
    this.mnuOption1.Click += new System.EventHandler(this.Option_Click);
    // 
    // mnuOption2
    // 
    this.mnuOption2.Index = 1;
    this.mnuOption2.Text = "Option2";
    this.mnuOption2.Click += new System.EventHandler(this.Option_Click);
    // 
    // mnuOption3
    // 
    this.mnuOption3.Index = 2;
    this.mnuOption3.Text = "Option3";
    this.mnuOption3.Click += new System.EventHandler(this.Option_Click);
    // 
    // mnuRadioOptions
    // 
    this.mnuRadioOptions.Index = 3;
    this.mnuRadioOptions.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                            this.mnuROption1,
                                            this.mnuROption2,
                                            this.mnuROption3});
    this.mnuRadioOptions.Text = "Radio Options";
    // 
    // mnuROption1
    // 
    this.mnuROption1.Index = 0;
    this.mnuROption1.RadioCheck = true;
    this.mnuROption1.Text = "Radio Option 1";
    this.mnuROption1.Click += new System.EventHandler(this.RadioOption_Click);
    // 
    // mnuROption2
    // 
    this.mnuROption2.Index = 1;
    this.mnuROption2.RadioCheck = true;
    this.mnuROption2.Text = "Radio Option 2";
    this.mnuROption2.Click += new System.EventHandler(this.RadioOption_Click);
    // 
    // mnuROption3
    // 
    this.mnuROption3.Index = 2;
    this.mnuROption3.RadioCheck = true;
    this.mnuROption3.Text = "Radio Option 3";
    this.mnuROption3.Click += new System.EventHandler(this.RadioOption_Click);
    // 
    // mnuWindow
    // 
    this.mnuWindow.Index = 4;
    this.mnuWindow.MdiList = true;
    this.mnuWindow.Text = "&Window";
    // 
    // MenuItemEventOption
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(513);
    this.ClientSize = new System.Drawing.Size(292186);
    this.IsMdiContainer = true;
    this.Menu = this.mainMenu1;
    this.Name = "MenuItemEventOption";
    this.Text = "MenuItemEventOption";

  }

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


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

    private void mnuFileOpen_Click(object sender, System.EventArgs e)
  {
    MessageBox.Show ("You clicked File Open""Menu Event Tester",   MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  }

  private void mnuFileClose_Click(object sender, System.EventArgs e)
  {
    MessageBox.Show ("You clicked File Close""Menu Event Tester",  MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

  }
  private void Option_Click(object sender, System.EventArgs e)
  {
    MenuItem item = sender as MenuItem;

    if item != null )
    {
      item.Checked = ! item.Checked;
    }
  }

  private void RadioOption_Click(object sender, System.EventArgs e)
  {
    MenuItem item = sender as MenuItem;
    Menu parent = item.Parent;

    if item != null )
    {
      foreach MenuItem mi in parent.MenuItems )
        mi.Checked = false;
      item.Checked = true;
    }
  }

  private void mnuEditCopy_Click(object sender, System.EventArgs e)
  {
    MessageBox.Show ("You clicked Edit Copy""Menu Event Tester"
      MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  
  }

  private void mnuEditPaste_Click(object sender, System.EventArgs e)
  {
    MessageBox.Show ("You clicked Edit Paste""Menu Event Tester"
      MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  
  }

  private void mnuFileSave_Click(object sender, System.EventArgs e)
  {
    MessageBox.Show ("You clicked Save""Menu Event Tester"
      MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

  }

  private void mnuFileSaveAs_Click(object sender, System.EventArgs e)
  {
    MessageBox.Show ("You clicked SaveAs""Menu Event Tester"
      MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  
  }
}

   
  
Related examples in the same category
1.new MenuItem
2.new MenuItem("&Open...",new EventHandler(MenuFileOpenOnClick),Shortcut.CtrlO)
3.extends MenuItem
4.MenuItem.Checked
5.MenuItem.Click
6.MenuItem.DrawItem
7.MenuItem.MeasureItem
8.MenuItem.MenuItems
9.MenuItem.OnSelect
10.MenuItem.Popup
11.MenuItem.Shortcut
12.MenuItem.Text
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.