Torna al Thread

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PersonalizzaMenuTable { public partial class Form1 : Form { private List<String> elencoFigliMenu = new List<string>(); private List<Nodo> elencoPadriMenu = new List<Nodo>(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { CaricaDatiTabella(); CreaOggettoMenu(); } private void CaricaDatiTabella() { //Creio i figli elencoFigliMenu.Add("&Crea File"); elencoFigliMenu.Add("&Trova File"); elencoFigliMenu.Add("&Esci"); //Creo i padri elencoPadriMenu.Add(new Nodo("&Menu",elencoFigliMenu,true)); elencoPadriMenu.Add(new Nodo("&Help",true)); } private void CreaOggettoMenu() { MenuStrip ms = new MenuStrip(); foreach (Nodo namePadre in elencoPadriMenu) { if (namePadre != null) { ToolStripMenuItem nodoPadre = new ToolStripMenuItem(namePadre.getKeyNodoPadre(), null, new EventHandler(eventMenu_Click)); nodoPadre.Visible = namePadre.getVisibilitaNodo(); foreach (String nomeFiglio in namePadre.getNodiFigli()) { ToolStripMenuItem nodoFiglioLetto = new ToolStripMenuItem(nomeFiglio, null, new EventHandler(eventSottoMenu_Click)); nodoPadre.DropDownItems.Add(nodoFiglioLetto); } // Add the window ToolStripMenuItem to the MenuStrip. ms.Items.Add(nodoPadre); // Dock the MenuStrip to the top of the form. ms.Dock = DockStyle.Top; // The Form.MainMenuStrip property determines the merge target. this.MainMenuStrip = ms; // Add the MenuStrip control to the controls collection last. // This is important for correct placement in the z-order. this.Controls.Add(MainMenuStrip); } } //// Create a MenuStrip control with a new window. //MenuStrip ms = new MenuStrip(); //ToolStripMenuItem windowMenu = new ToolStripMenuItem("Window"); //ToolStripMenuItem windowEndMenu = new ToolStripMenuItem("End"); //ToolStripMenuItem windowEndEndMenu = new ToolStripMenuItem("End"); //ToolStripMenuItem windowNewMenu = new ToolStripMenuItem("New", null, new EventHandler(windowNewMenu_Click)); //windowMenu.DropDownItems.Add(windowNewMenu); //windowMenu.DropDownItems.Add(windowEndMenu); //windowEndMenu.DropDownItems.Add(windowEndEndMenu); //((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowImageMargin = false; //((ToolStripDropDownMenu)(windowMenu.DropDown)).ShowCheckMargin = true; //// Add the window ToolStripMenuItem to the MenuStrip. //ms.Items.Add(windowMenu); //// Dock the MenuStrip to the top of the form. //ms.Dock = DockStyle.Top; //// The Form.MainMenuStrip property determines the merge target. //this.MainMenuStrip = ms; //// Add the MenuStrip control to the controls collection last. //// This is important for correct placement in the z-order. //this.Controls.Add(MainMenuStrip); } private void eventSottoMenu_Click(object sender, EventArgs e) { //Codice clik evento SottoMenu ToolStripMenuItem elemento = (ToolStripMenuItem)sender; Console.WriteLine(elemento.Text.ToString()); } private void eventMenu_Click(object sender, EventArgs e) { //Codice clik evento Menu ToolStripMenuItem elemento = (ToolStripMenuItem)sender; Console.WriteLine(elemento.Text.ToString()); } } }
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5