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.

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.

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";
string ctrlID_tab = "tab14";
if (screen.GetText(1, 1, 20).Trim() == "LOGON TST")
{
Application app = MyReflection.ActiveApplication;
IFrame frame = (IFrame)app.GetObject("Frame");
IView view = (IView)frame.GetViewByTitleText(viewTitle);
IIbmTerminal terminal = (IIbmTerminal)view.Control;
IUiMode ui = (IUiMode)view.UiMode;
IUiControl controlTab = (IUiControl)ui.GetControlById(ctrlID_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";
string ctrlID_button = "button16";
if (screen.GetText(1, 1, 20).Trim() == "LOGON TST")
{
object[] param = { "data" };
InputMapAction action = new InputMapAction(InputMapActionID.SendHostTextAction, param);
InputMapActionSequence actionSequence = new InputMapActionSequence();
Application app = MyReflection.ActiveApplication;
IFrame frame = (IFrame)app.GetObject("Frame");
IView view = (IView)frame.GetViewByTitleText(viewTitle);
IIbmTerminal terminal = (IIbmTerminal)view.Control;
IUiMode ui = (IUiMode)view.UiMode;
IUiControl controlButton = (IUiControl)ui.GetControlById(ctrlID_button);
actionSequence.Add(action);
terminal.UiControlActionMapper.Add(controlButton, actionSequence);
}
}
|