正在阅读:.Net基础学习:动态菜单.Net基础学习:动态菜单

2004-02-14 09:34 出处:PConline 作者:lustful/CSDN 责任编辑:linjixiong

   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(584, 341);
   this.IsMdiContainer = true;
   this.Menu = this.mainMenu1;
   this.Name = "Form1";
   this.Text = "Form1";
  }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  //
  //使用反射生成菜单事件
  //
  private void NewClick(object sender, System.EventArgs e)
  {
   MenuItem item = (MenuItem)sender;
   MenuItem par = (MenuItem)item.Parent;

   int i = par.Index;
   int j = item.Index;
   string iDll = mDlls[i][j];
   string iClass = iDll.Substring(0,iDll.IndexOf("."))
    + "."
    + iDll.Substring(0,iDll.IndexOf("."));
   string iFunc = mFuncs[i][j];
   try
   {
    Assembly asm = Assembly.LoadFrom(iDll);
    Type mytype = asm.GetType(iClass);
    MethodInfo mi = mytype.GetMethod(iFunc);
    object obj = Activator.CreateInstance(mytype);
    mi.Invoke(obj,new object[] {this});
   }

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品