You can dynamically show or hide controls on the user interface to provide a customized user experience. You can also enable or disable controls and change the actions that are mapped to controls.
You can manipulate any control that is configured with the UI Designer. Reflection does not provide programmatic access to other controls.
This walkthrough shows how to:
Add a Custom Control in the UI Designer
Before you open Visual Studio, you'll need to add the custom controls you want to access in the Reflection UI Designer.
This sample shows how to dynamically display a tab on a session that you have configured previously in the UI Designer.
Attachmate.Reflection
Attachmate.Reflection.Framework
Attachmate.Reflection.Emulation.IbmHosts
Note: Be sure to change the ctrlID_tab string to the control ID for the tab that is displayed in the UI Designer.
You can dynamically add or change the action mapped to a button. This sample changes the action of the button you configured above from opening a URL to sending a string of data to the host.
Replace the code in the screen_NewScreenReady event handler that you set up earlier (in Display the Control) with the following code. This includes additional code that changes the action for the button created earlier in the UI designer. The code identifies the button , creates an action, and adds it to an Input action sequence. Then it gets the button with its control ID and maps the action sequence to the button.
Note: Be sure to change the ctrlID_tab and ctrlID_button strings to the IDs for these controls that are displayed in the UI Designer.
Map an action to a button |
Copy Code
|
---|---|
static void screen_NewScreenReady(object sender, EventArgs e) { IIbmScreen screen = (IIbmScreen)sender; //Replace tab2 with the tab ID of the tab you created //The control ID for the tab is displayed in the Identifier field in the UI Designer. string ctrlID_tab = "tab14"; //**************************************************************************** //*******Add the ID of the button control that is displayed in the UI Designer******* //Replace button4 with the ID of the button you created string ctrlID_button = "button16"; //**************************************************************************** //Find the screen to display the tab for if (screen.GetText(1, 1, 10).Contains("LOGON")) { Application app = MyReflection.ActiveApplication; IFrame frame = (IFrame)app.GetObject("Frame"); //Get the View and the UiMode object that contains the controls for this view. IView view = frame.SelectedView; IUiMode ui = (IUiMode)view.UiMode; //Get the control with the control ID and show the control IUiControl controlTab = (IUiControl)ui.GetControlById(ctrlID_tab); controlTab.Visible = true; //*************************************************************** //*******Add this code to change the action for the control******* //Create an object array that contains data and an action to send it to the host //Then create an action sequence and add the action to it object[] param = { "data" }; InputMapAction action = new InputMapAction(InputMapActionID.SendHostTextAction, param); InputMapActionSequence actionSequence = new InputMapActionSequence(); actionSequence.Add(action); //Get the button control with its control ID and bind the action sequence to the button IUiControl controlButton = (IUiControl)ui.GetControlById(ctrlID_button); controlButton.Text = "Send Data Text"; screen.Parent.UiControlActionMapper.Add(controlButton, actionSequence); //**************************************************************************** } } |