magiclibrary.dll真是做的不错!!!
我把怎么用它做菜单的步骤写在下面:
1。 加入控件,引入magiclibrary.dll
2。 引入命名空间:
                                 using Crownwood.Magic.Menus;
                                 using Crownwood.Magic.Win32;
                                 using Crownwood.Magic.Common;
                                 using Crownwood.Magic.Controls;
3。 定义变量:
                                   private ImageList _images = null;
                                   private Crownwood.Magic.Menus.MenuControl _topMenu = null;
                                   private System.Windows.Forms.ImageList il1;//在里面加入菜单项的图标
4。 生成定级菜单:
                                  protected void SetupMenus()
                                    {
                                     // Create the MenuControl
                                     _topMenu = new Crownwood.Magic.Menus.MenuControl();
                                     // We want the control to handle the MDI pendant
                                     _topMenu.MdiContainer = this;
                                     // Create the top level Menu
                                     MenuCommand top1 = new MenuCommand("文件(&F)");
                                     _topMenu.MenuCommands.AddRange(new MenuCommand[]{top1,top2});
                                    CreateFileMenu(top1);
                                    _topMenu.Dock = DockStyle.Top;
                                       _topMenu.Selected += new CommandHandler(OnSelected);
                                       _topMenu.Deselected += new CommandHandler(OnDeselected);
                                       Controls.Add(_topMenu);
                                    }
5。 子菜单:
protected void CreateFileMenu(MenuCommand mc)
  {
   // Create menu commands
   MenuCommand file1 = new MenuCommand("新建(&N)",this.il1,0,Shortcut.CtrlN);
   MenuCommand file2 = new MenuCommand("打开(&O)");
   MenuCommand file3 = new MenuCommand("-");
   MenuCommand file4 = new MenuCommand("保存(&S)");
   MenuCommand file5 = new MenuCommand("另存为...",Shortcut.CtrlShiftS);
   MenuCommand file6 = new MenuCommand("-");
   MenuCommand file7 = new MenuCommand("打印(&P)");
   MenuCommand file8 = new MenuCommand("打印预览");
    MenuCommand file9 = new MenuCommand("-");
   MenuCommand file10 = new MenuCommand("退出(&X)", new EventHandler(OnExit));
 mc.MenuCommands.AddRange(new MenuCommand[]{file1,file2,file3,file4,file5,file6,file7,file8,file9,file10});         
  }
6。 处理单击事件:
protected void OnExit(object sender, System.EventArgs e)
  {
   MessageBox.Show("哈哈,要走吗?");
   Application.Exit();
  }
7。 在form()里面使用你的菜单:
public Form1()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();
   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
   SetupMenus();
  }
编译运行一下,你可能看到如下的效果:











0 Comments:
Post a Comment