本实例通过注册带回调的菜单栏,实现了一个菜单多个操作对应一个项目dll,主要步骤如下:
1、注册开始菜单,应用模块入口
2、加载MenuBar菜单
3、回调方法实现
UGOPEN\SampleNXOpenApplications\.NET\MenuBarDotNetApp
1、注册开始菜单,应用模块入口
VERSION 120 EDIT UG_GATEWAY_MAIN_MENUBAR MENU UG_APPLICATION ! ***NOTE button name must match the name you registered for! your application in the MenuBarManager()->RegisterApplication call APPLICATION_BUTTON SAMPLE_CSHARP_APP LABEL Sample C Sharp Application LIBRARIES MenuBarCSharpApp MENU_FILES MenuBarCSharpApp.men END_OF_MENU
这里通过LIBRARIES标签,指定了MenuBarCSharpApp这个生成文件
2、 加载MenuBar菜单
VERSION 120 EDIT UG_GATEWAY_MAIN_MENUBAR TOP_MENU CASCADE_BUTTON SAMPLE_CSHARP_APP_MENULABEL Sample C Sharp END_OF_TOP_MENU MENU SAMPLE_CSHARP_APP_MENU BUTTON SAMPLE_CSHARP_APP_BUTTON1LABEL Print Button IDACTIONS SAMPLE_CSHARP_APP__action1 BUTTON SAMPLE_CSHARP_APP_BUTTON2LABEL Test Callback ReturnsACTIONS SAMPLE_CSHARP_APP__action2 BUTTON SAMPLE_CSHARP_APP_BUTTON3LABEL Print Application IDACTIONS SAMPLE_CSHARP_APP__action3 BUTTON SAMPLE_CSHARP_APP_BUTTON4LABEL Print This Button DataACTIONS SAMPLE_CSHARP_APP__action4 TOGGLE_BUTTON SAMPLE_CSHARP_APP_BUTTON5LABEL Print Toggle StatusACTIONS SAMPLE_CSHARP_APP__action5 END_OF_MENU
这里ACTIONS指定的是方法,而不是dll文件
3、回调方法实现
public static int Startup() { int retValue = 0; try { if (theSession == null) { theSession = Session.GetSession(); } if (lw == null) { lw = theSession.ListingWindow; } theUI.MenuBarManager.RegisterApplication("SAMPLE_CSHARP_APP", new NXOpen.MenuBar.MenuBarManager.InitializeMenuApplication(Program.ApplicationInit), new NXOpen.MenuBar.MenuBarManager.EnterMenuApplication(Program.ApplicationEnter), new NXOpen.MenuBar.MenuBarManager.ExitMenuApplication(Program.ApplicationExit), true, true, true ); theUI.MenuBarManager.AddMenuAction("SAMPLE_CSHARP_APP__action1", new NXOpen.MenuBar.MenuBarManager.ActionCallback(Program.PrintButtonIdCB)); theUI.MenuBarManager.AddMenuAction("SAMPLE_CSHARP_APP__action2", new NXOpen.MenuBar.MenuBarManager.ActionCallback(Program.TestCallbackReturnsCB)); theUI.MenuBarManager.AddMenuAction("SAMPLE_CSHARP_APP__action3", new NXOpen.MenuBar.MenuBarManager.ActionCallback(Program.PrintApplicationIdCB)); theUI.MenuBarManager.AddMenuAction("SAMPLE_CSHARP_APP__action4", new NXOpen.MenuBar.MenuBarManager.ActionCallback(Program.PrintButtonDataCB)); theUI.MenuBarManager.AddMenuAction("SAMPLE_CSHARP_APP__action5", new NXOpen.MenuBar.MenuBarManager.ActionCallback(Program.PrintToggleStatusCB)); } catch (NXOpen.NXException ex) { // ---- Enter your exception handling code here ----- } return retValue; }
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删