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 Basic, you'll need to identify the controls you want to access in the Reflection UI Designer.

First 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 to the designer.

auto expand abbreviation

Note that the Identifier for the 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."

Now, in the Visual Basic editor, create a handler for the Screen Ready event:

'This sample displays a tab when a specific screen is ready

Private Sub IbmScreen_NewScreenReady(ByVal sender As Variant)

      Dim ui As UiMode

      Dim control As UiControl

      

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

      Set ui = ThisView.UiMode

      

      'Get the control. The control ID is displayed in the Identifier field on the UI Designer.

      Set control = ui.GetControlById("tab14")

      

      'Get the text to identify the screen

      ScreenID = Trim(ThisIbmScreen.GetText(1, 1, 20))

      

      'When the screen is ready, make the control visible

      If ScreenID = "LOGON TST" Then

            control.Visible = True

      End If

End Sub

To dynamically ad an action to the button, we can call a subroutine in the test for the screen ID:

      

      If ScreenID = "LOGON TST" Then

            control.Visible = True

            Call UiControlAction_AddAction

      End If

      

      

' This sample adds an action to a button on the ribbon

Sub UiControlAction_AddAction()

      Dim ui As UiMode

      Dim control As UiControl

      Dim action As New InputMapAction

      Dim actionSequence As New InputMapActionSequence

      

      'Get the UiMode object that contains the controls for this view.
      Set ui = ThisView.UiMode

      

      'Get the control. The control ID is displayed in the Identifier field on the UI Designer.
      ctrlId = "button16"

      Set control = ui.GetControlById(ctrlId)

      

      'Add action to send text to the host

      action.ActionId = InputMapActionID_SendHostTextAction

      

      'Add the required parameter for the action.

      action.AddParameter "Data"

      

      'Add the action to an action sequence

      actionSequence.Add action

      

      'Bind the actionSequence to the control

      ThisIbmTerminal.UiControlActionMapper.Add control, actionSequence

      

End Sub