Walkthroughs > Customize the User Interface > Dynamically Change the User Interface |
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. InfoConnect 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 InfoConnect UI Designer.
Open the InfoConnect workspace and create a demo session as follows:
If you are using IBM, create an IBM3270 session with a host name of "demo:ibm3270.sim" and save the session as demoSession.rd3x in the default folder (...\myDocuments\Micro Focus\InfoConnect.)
If you are using Open Systems, create a VT session with a host name of "demo:UNIX" and save the session as demoSession.rdox in the default folder.
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
Add event handler |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Attachmate.Reflection.UserInterface; using Attachmate.Reflection.Emulation.IbmHosts; using Attachmate.Reflection.Framework; namespace DisplayControl { class Program { static void screen_NewScreenReady(object sender, EventArgs e) { throw new NotImplementedException(); } static void Main(string[] args) { //Start a visible instance of InfoConnect or get the instance running at the given channel name Application app = MyReflection.CreateApplication("myWorkspace", true); //Create a terminal from the session document file string sessionPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\InfoConnect\demoSession.rd3x"; IIbmTerminal terminal = (IIbmTerminal)app.CreateControl(sessionPath); //Make the session visible in the workspace IFrame frame = (IFrame)app.GetObject("Frame"); IView view = frame.CreateView(terminal); //Create a handler for the NewScreenReady Event IIbmScreen screen = terminal.Screen; screen.NewScreenReady += screen_NewScreenReady; System.Console.ReadLine(); } } } |
Example Title |
Copy Code
|
---|---|
static void screen_NewScreenReady(object sender, EventArgs e) { IIbmScreen screen = (IIbmScreen)sender; //The control ID for the tab is displayed in the Identifier field in the UI Designer. string ctrlID_tab = "tab3"; IUiControl controlTab; //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 controlTab = (IUiControl)ui.GetControlById(ctrlID_tab); controlTab.Visible = true; } } |
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.
Add the following code to the bottom of the event handler that you set up earlier (in Display a Control). This code 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.
Map an action to a button |
Copy Code
|
---|---|
static void screen_NewScreenReady(object sender, EventArgs e) { ..................................................................... controlTab.Visible = true; //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); screen.Parent.UiControlActionMapper.Add(controlButton, actionSequence); } } |