Friday, 4 January 2013

dynamic menu in c#.net

  private void frmDynamiMenu_Load(object sender, EventArgs e)
        {
            var m = obj.GetAllMDIMenu().Where(b => b.Parent_Menu_ID == 0).ToList();
            for (i = 0; i < m.Count; i++)
            {
                ToolStripMenuItem tsm = new ToolStripMenuItem();
                tsm.Text = m[i].Menu_Text;
                tsm.Tag = m[i].Menu_ID;
                var n=obj.GetAllMDIMenu().Where(c => c.Parent_Menu_ID == obj.GetAllMDIMenu().Where(b => b.Parent_Menu_ID == 0).ToList()[i].Menu_ID).ToList();
                for (j = 0; j < n.Count; j++)
                {
                    ToolStripMenuItem tsm1 = new ToolStripMenuItem();
                    tsm1.Text = n[j].Menu_Text;
                   tsm1.Tag = n[j].Page_Name;
                  tsm1.Click+=new EventHandler(tsm2_Click);
                    tsm.DropDownItems.Add(tsm1);
                }
                menuStrip.Items.Add(tsm);
            }
         
        }
private void tsm2_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem tsm3 = (ToolStripMenuItem)sender;
            string[] ss = tsm3.Tag.ToString().Split('.');
         string sFormName = "WindowsFormsApplication23." + ss[0];

            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();

            Form frm = (Form)asm.CreateInstance(sFormName );

            frm.MdiParent = this;

            frm.StartPosition = FormStartPosition.CenterScreen;

            frm.Show(); 
        }
page look like:

No comments:

Post a Comment