InfoConnect API Guide
Walkthrough / Add the Terminal User Control / Embed Terminal User Controls
In This Topic
    Embed Terminal User Controls
    In This Topic

    The InfoConnect Terminal User Control (TUC) can be embedded in your Windows applications to provide a terminal screen on a Windows form along with another application or a different data source. This control renders a terminal emulator session within a given windows form application.

    You can also embed InfoConnect Terminal User Controls on Windows Presentation Foundation (WPF) applications.

    Note:
    You can use the InfoConnect Terminal User Control with Visual Studio 2017 targeted to .NET 4.7.1.

    When creating applications on a 64-bit machine and using a InfoConnect Terminal User Control, make sure the application target is set to "x86" instead of "Any CPU" or "x64". This is required because a 64-bit application does not work directly with 32-bit controls. If the build target (Platform) is not set to "x86", the "COMException: class not registered" error is displayed during runtime.

    To set up the IBM terminal User Control

    1. In Visual Studio, create a new Windows Form Application.
    2. In Form Design view, drag and drop the IbmTerminalControl from the Toolbox to Form1.

      Note: The required assemblies are automatically added to the project references after you add the control to the form.


    3. In Form designer, double-click on Form1. This adds the default Form event handler, which is the Load event. Then add a call to InitInstance. This call initializes the terminal control ibmTerminalControl1, with a new host type or a session file. The following example code creates a new terminal with a IBM 3270 host type.  
       Initialize an IBM 3270 terminal
      Copy Code
      private void Form1_Load(object sender, EventArgs e)
      {
           ibmTerminalControl1.InitInstance(Attachmate.Reflection.UserControl.IbmHosts.HostType.IBM3270);
      }
      
                         
    4. Back in the Form designer, select the ibmTerminalControl1 control you added and then in the Properties view, set the Dock property to Fill. This allows the control to fill the Form. Resizing of the form resizes the contained terminal control at runtime. This is ideal for resizing the Terminal view, but not required.

         
    5. Double-click on the ibmTerminalControl1 control. This adds an event handler for the ibmTerminalControl1 TerminalInitializedEvent event. This event is fired after the terminal is initialized from the InitInstance call (made after the form loads).
    6. In code view for Form1.cs, add the event handler code as follows. The following code sets the host address and connects to that host.
      Note: This code also checks for terminal initalization errors to make sure that the terminal is properly initialized before setting the host name and connecting.
                     
      Set the host address and connect to the host
      Copy Code
      private void ibmTerminalControl1_TerminalInitializedEvent(object sender, AsyncCompletedEventArgs e)
              {
                  // Check if error occurred during the terminal initialization
                  if (e.Error != null)
                  {
                      MessageBox.Show("Error during terminal initialization step: " + e.Error); return;
                  }
      
                  ibmTerminalControl1.IbmTerminal.HostAddress = "yourHostName";
                  ibmTerminalControl1.IbmTerminal.Port = 23;
                  ibmTerminalControl1.IbmTerminal.Connect();
       }
      

                         
    7. In the Form Designer, select Form1 and then in the Properties window, select  to open the Events view.
    8. For the FormClosing event, enter Form1_FormClosing and then double click to add this event handler.
    9. In the form code window, add the following code to the Form1_FormClosing event handler. This code closes the terminal and sets it to null before the form is closed.                          
      Close the terminal
      Copy Code
      private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
      {
             ibmTerminalControl1.IbmTerminal.Close(Attachmate.Reflection.CloseOption.CloseNoSave);
             ibmTerminalControl1 = null;
      }
      
                         
    10. Build and run the solution. At runtime, you should get a form that renders a terminal host.

                     

      Note:  

      You may see the following compiler warning:

      Warning A reference was created to embedded interop assembly 'c:\Windows\assembly\
      GAC_MSIL\InfoConnect\<version>__13bff1b6907eadcf\Reflection.dll' because of an indirect reference to that assembly created by assembly 'c:\Program Files\Micro Focus\InfoConnect\Programmer Interfaces\Attachmate.Reflection.UserControl.IbmHosts.dll'. Consider changing the 'Embed Interop Types' property on either assembly.

      The simplest way to resolve this warning is to set the Embed Interop Types property of the InfoConnectReference to False. For more about how to resolve this warning, see Technical Note 2579.

     

    To set up the IBM User Control in VB.Net

    1. In Visual Studio, create a new Windows Form Application.
    2. In Form Design view, drag and drop the IbmTerminalControl from the Toolbox to Form1.

      Note: The required assemblies are automatically added to the project references after you add the control to the form.


    3. In Form designer, double-click on Form1.vb. This adds the default Form event handler, which is the Load event. Then add a call to InitInstance to initialize the terminal control.             
       Initialize an IBM 3270 terminal
      Copy Code
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          IbmTerminalControl1.InitInstance(Attachmate.Reflection.UserControl.IbmHosts.HostType.IBM3270)
      End Sub
      
                                                     
    4. Back in the Form designer, select the IbmTerminalControl1 control you added and then in the Properties view, click   to open the Events view and double click the Load event. In the code view, add the event handler code as shown below. This allows the control to fill the Form. Resizing of the form resizes the contained terminal control at runtime. This is ideal for resizing the terminal view, but not required.
       
      Set the control to fill the form
      Copy Code
      Private Sub IbmTerminalControl1_Load(sender As Object, e As EventArgs) Handles IbmTerminalControl1.Load
          IbmTerminalControl1.Dock = DockStyle.Fill
      End Sub
      
                                                                         
    5. Double-click on the IbmTerminalControl1 control. This adds an event handler for the IbmTerminalControl1 TerminalInitializedEvent event. This event is fired after the terminal is initialized from the InitInstance call (made after the form loads).
    6. In code view for Form1.vb, add the event handler code as follows. The following code sets the host address and connects to that host.
      This code also checks for terminal initalization errors to make sure that the terminal is properly initialized before setting the host name and connecting.
         
      Set the host address and connect to the host
      Copy Code
      Private Sub IbmTerminalControl1_TerminalInitializedEvent(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs) Handles IbmTerminalControl1.TerminalInitializedEvent
              REM Check if error occurred during the terminal initialization
              Dim ts As String
              ts = Nothing
              If (e.Error IsNot ts) Then
                  MessageBox.Show("Error during terminal initialization step: " & e.Error.ToString)
                  Return
              End If
              IbmTerminalControl1.IbmTerminal.HostAddress = "yourHostName"
              IbmTerminalControl1.IbmTerminal.Port = 23
              IbmTerminalControl1.IbmTerminal.Connect()
      End Sub
      
                                                                                                               
    7. In the Form Designer, select Form1.vb and then in the Properties window, select  to open the Events view.
    8. For the FormClosing event, enter Form1_FormClosing and then double click to add this event handler.

    9.  In the form code window, add the following code to the Form1_FormClosing event handler:                                                                         
      Close the terminal
      Copy Code
      Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
          IbmTerminalControl1.IbmTerminal.Close(Attachmate.Reflection.CloseOption.CloseNoSave)
          IbmTerminalControl1 = Nothing
      End Sub
      
                             
    10. Build and run the solution. At runtime, you should get a form that renders a terminal host.


                             

       

      Note:

      You may see the following compiler warning:

      Warning A reference was created to embedded interop assembly 'c:\Windows\assembly\
      GAC_MSIL\InfoConnect\<version>__13bff1b6907eadcf\Reflection.dll' because of an indirect reference to that assembly created by assembly 'c:\Program Files\Attachmate\InfoConnect\Programmer Interfaces\Attachmate.Reflection.UserControl.IbmHosts.dll'. Consider changing the 'Embed Interop Types' property on either assembly.

      The simplest way to resolve this warning is to set the Embed Interop Types property of the InfoConnectReference to False. For more about how to resolve this warning, see Technical Note 2579.    

                      

    To set up the Open Systems User Control

    1. In Visual Studio, create a new Windows Form Application.
    2. In Form Design view, drag and drop the OpenSystemsTerminalControl from the Toolbox to Form1.

      Note: The required assemblies are automatically added to the project references after you add the control to the form.


    3. In Form designer, double-click on Form1. This adds the default Form event handler, which is Load event. Then add a call to InitInstance to initialize the terminal control.                        
      Create an Open Systems terminal
      Copy Code
      private void Form1_Load(object sender, EventArgs e)
      {                                      
          openSystemsTerminalControl1.InitInstance();
      }
      
                         
    4. Add the following using directive:

      using Attachmate.Reflection.Emulation.OpenSystems;

    5. Back in the Form designer, select the openSystemsTerminalControl1 control you added and then in the Properties view, set the Dock property to Fill. This allows the control to fill the Form. Resizing of the form resizes the contained terminal control at runtime. This is ideal for resizing the Terminal view, but not required.

    6. Double-click on the OpenSystemsTerminalControl1 control. This adds an event handler for the openSystemsTerminalControl1 TerminalInitializedEvent event. This event is fired after the terminal is initialized from the InitInstance call (made after the form loads).
    7. In code view for Form1.cs, add the event handler code as follows. The following code sets the host address and connects to the host.
      Note: This code also checks for terminal initialization errors to make sure that the terminal is properly initialized before setting the host name and connecting.
      Set the host address and connect to the host
      Copy Code
      private void openSystemsTerminalControl1_TerminalInitializedEvent(object sender, AsyncCompletedEventArgs e)
      {
          // Check if error occurred during the terminal initialization
          if  (e.Error != null)
          {
              MessageBox.Show("Error during terminal initialization step: " + e.Error); return;
          }
          ITerminal Terminal = openSystemsTerminalControl1.Terminal;
      
          //Use this code for a telnet connection
          Terminal.ConnectionType = ConnectionTypeOption.Telnet;
          ((IConnectionSettingsTelnet)Terminal.ConnectionSettings).HostAddress = "yourHost.com"; // replace this hard-coded host name with your host name
          ((IConnectingSettingsBestNetwork)Terminal.ConnectionSettings).TelnetPort = 23;
      
          /* Use this code for a secure connection, instead of the previous code for telnet
          Terminal.ConnectionType = ConnectionTypeOption.SecureShell;
          ((IConnectionSettingsSecureShell)Terminal.ConnectionSettings).HostAddress = "yourHost.com"; // replace this hard-coded host name with your host name
          ((IConnectionSettingsSecureShell)Terminal.ConnectionSettings).UserName = "yourUserName"; // replace this hard-coded user name with your user name
          ((IConnectionSettingsSecureShell)Terminal.ConnectionSettings).SSHPort = 22;
          ((IConnectionSettingsSecureShell)Terminal.ConnectionSettings).SSHShowBannerDialog = false;
          ((IConnectionSettingsSecureShell)Terminal.ConnectionSettings).SSHTermWindowAuth = true;*/
      
          Terminal.Connect();
      }
      
                                                 
    8. In the Form Designer, select Form1 and then in the Properties window, select  to open the Events view.
    9. For the FormClosing event, enter Form1_FormClosing and then double click to add this event handler.

    10.  In the form code window, add the following code to the Form1_FormClosing event handler:                        
      Close the form
      Copy Code
      private void Form1_FormClosing(object sender, FormClosingEventArgs e)
      {
          openSystemsTerminalControl1.Terminal.Close(Attachmate.Reflection.CloseOption.CloseNoSave);
          openSystemsTerminalControl1 = null;
      }
      
                            
    11. Build and run the solution. At runtime, you should get a form that renders a terminal host.


                             

       

      Note:

      You may see the following compiler warning:

      Warning A reference was created to embedded interop assembly 'c:\Windows\assembly\
      GAC_MSIL\InfoConnect\<version>__13bff1b6907eadcf\Reflection.dll' because of an indirect reference to that assembly created by assembly 'c:\Program Files\Attachmate\InfoConnect\Programmer Interfaces\Attachmate.Reflection.UserControl.IbmHosts.dll'. Consider changing the 'Embed Interop Types' property on either assembly.

      The simplest way to resolve this warning is to set the Embed Interop Types property of the InfoConnectReference to False. For more about how to resolve this warning, see Technical Note 2579.