In This Topic
You can define context menus and assign them at runtime. You can also load context menus or switch from one menu to another when specific screens are loaded.
Define a Context Menu
Switch Context Menus
Define a Context Menu
This sample opens Reflection, creates a new session, and defines and assigns a context menu.
- In Visual Studio, create a new Console Application project and add references for the following Reflection assemblies. (Depending on your version of Visual Studio, these can be found either on the .NET tab or under Assemblies | Extensions.)
Attachmate.Reflection.Framework
Attachmate.Reflection.Emulation.OpenSystems (if using Open Systems)
Attachmate.Reflection.Emulation.IbmHosts (if using IBM)
Attachmate.Reflection
- Replace all the code in the Program.cs file with the following code for the terminal you are using. This code creates a new terminal session, and a new context menu, which is assigned to a copy of the existing menu. It creates a menu item and adds it to the menu and removes an item. Then it assigns the new menu as the default menu for the session.
To test this project
- Press F5 to compile and run the project.
- In the Reflection session, right-click to open the context sensitive menu and verify that it has a Create Email item and does not have a Cut item.
Switch the Context Menu Back and Forth
You can create an alternate menu and use only on specific screens.
- In Visual Studio, create a new Console Application project and add references for the following Reflection assemblies. (Depending on your version of Visual Studio, these can be found either on the .NET tab or under Assemblies | Extensions.)Attachmate.Reflection.Framework
Attachmate.Reflection.Emulation.OpenSystems (if using Open Systems)
Attachmate.Reflection.Emulation.IbmHosts (if using IBM)
Attachmate.Reflection
- Replace all the code in the Program.cs file with the following code for the terminal you are using. This code adds properties for the two menus we will create; an Alternate menu that we can customize and a copy of the Default menu.
- Add the following code to create the menus. This code opens a session and creates two copies of the original menu—an Alternate menu that we can customize and a Default menu that we can reference when we need to switch back to the default. Then it creates a menu item mapped to an email action and adds it to the AlternateMenu. It also removes the Cut item from the menu. Finally, it creates event handlers that we'll use to swap menus for specific screens and to make sure the session is set to use the default menu if it is automatically saved when it is closed.
- Set up the first event to switch menus when a specific command is recognized (for Open Systems) or when a certain screen is recognized.
- Set up the second event to make sure the session is set to use the default menu when it is saved. We need to handle this event to prevent changing the default menu settings if the Reflection workspace is set to save document settings automatically when closing a document. (In our sample, if the session is closed when the alternate menu is used, the alternate menu is saved as the default menu for this session unless we handle this event.)
To test this project
- Press F5 to run the sample
- When the session opens, right-click on the screen to view the context menu and verify that the default menu is displayed.
- Enter any credentials to log on to the demo.
- If you are using Open Systems, enter "demodata" to go to a data screen.
- Right-click on the screen and verify that it has a Create Email item and does not have a Cut item.