Show Contents / Index / Search

Dynamically Changing 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. Reflection does not provide programmatic access to other controls.

Before you open Visual Studio, you'll need to identify the controls you want to access in the Reflection UI Designer.

To set up your application, you will need to open the Reflection workspace and then open the UI Designer, on the Appearance tab.Then add custom controls or select the controls you want to access. In our example, we'll add a tab with a button.

auto expand abbreviation

Note the Identifier for the Custom Tab (tab14). We'll need this ID to identify the control when we access it from the API.

We'll also need the ID for the button. To get this ID, select the button on the UI designer.

auto expand abbreviation

Now we have a tab with an Identifier of "tab14" and a button with an Identifier of "button16."

In Visual Studio, create a handler for the NewScreenReady event:

screen.NewScreenReady += new EventHandler(Screen_NewScreenReady);

This sample shows how to dynamically display a tab that you have configured in the UI Designer.

static void Screen_NewScreenReady(object sender, EventArgs e)

{

      IIbmScreen screen = (IIbmScreen)sender;

      string viewTitle = "Accounts.rd3x";

      //The control ID for the tab is displayed in the Identifier field in the UI Designer.
      string ctrlID_tab = "tab14";

      //Find the screen we want to display the tab for

      if (screen.GetText(1, 1, 20).Trim() == "LOGON TST")

      {

            Application app = MyReflection.ActiveApplication;

            IFrame frame = (IFrame)app.GetObject("Frame");

      

            //Get the view, based on the view title

            IView view = (IView)frame.GetViewByTitleText(viewTitle);

      

            IIbmTerminal terminal = (IIbmTerminal)view.Control;

      

            //Get the UiMode object that contains the controls for this view.

            IUiMode ui = (IUiMode)view.UiMode;

      

            //Get the control with the control ID

            IUiControl controlTab = (IUiControl)ui.GetControlById(ctrlID_tab);

      

            //Display the tab

            controlTab.Visible = true;

      }

}

To dynamically add an action to a button, you'll need to use the ImputMapAction and InputMapActionSequence objects, as shown below:

static void Screen_NewScreenReady(object sender, EventArgs e)

{

      IIbmScreen screen = (IIbmScreen)sender;

      string viewTitle = "Accounts.rd3x";

      

      //The control ID for the button is displayed in the Identifier field in the UI Designer.

      string ctrlID_button = "button16";

      

      //Find the screen on which to add the button action

      if (screen.GetText(1, 1, 20).Trim() == "LOGON TST")

      {

            //Create an object array that contains data to send to the host

            object[] param = { "data" };

      

            //Create an action to send the text to the host

            InputMapAction action = new InputMapAction(InputMapActionID.SendHostTextAction, param);

      

            //Create an action sequence to contain the action

            InputMapActionSequence actionSequence = new InputMapActionSequence();

      

            Application app = MyReflection.ActiveApplication;

            IFrame frame = (IFrame)app.GetObject("Frame");

      

            //Get the view, based on the view title

            IView view = (IView)frame.GetViewByTitleText(viewTitle);

      

            IIbmTerminal terminal = (IIbmTerminal)view.Control;

            //Get the UiMode object that contains the controls for this view.

            IUiMode ui = (IUiMode)view.UiMode;

      

            //Get the control from the control ID

            IUiControl controlButton = (IUiControl)ui.GetControlById(ctrlID_button);

      

            //Add the action to the action sequence

            actionSequence.Add(action);

            //Bind the action sequence to the button

            terminal.UiControlActionMapper.Add(controlButton, actionSequence);

      

      }

}