Using the WPF Terminal User Control
The Reflection Windows Presentation Foundation (WPF) Terminal User Control can be embedded in your WPF applications to provide a terminal screen on a window along with another application or a different data source. This control renders a terminal emulator session within a given WFP application.
Note: When creating applications on a 64-bit machine and using Reflection 2011 "Terminal Controls", 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 WPF terminal User Control
- In the Visual Studio New Project wizard, create a "WPF Application."
- If this is the first time you use Visual Studio to create a WPF terminal user control, you may need to add the Attachmate terminal controls to your Toolbox as follows:
- On the Toolbox, right click on the the General tab and then select Choose Items.
- In the Choose Toolbox Items dialog box, select the WPF Components tab, and then type Attachmate in the Filter text box.
- Select the Attachmate Terminal controls and click OK.
- In the Design view, drag and drop the control you want to use (for example, IbmTerminalControl) from the Toolbox to MainWindow.
- In Solution Explorer, right click on References, and then, on the Add Reference dialog box .NET tab, select Attachmate.Reflection and click OK.
Note: All of the other required assemblies are automatically added to the project references after you add the control to MainWindow.
- To allow the control to fill the window, remove the alignment attributes shown in the XAML view. For example:
Change:
<Grid>
<my:IbmTerminalControl HorizontalAlignment="Left" Margin="18,18,0,0" Name="ibmTerminalControl1" VerticalAlignment="Top" />
</Grid>
To:
<Grid>
<my:IbmTerminalControl Name="ibmTerminalControl1" />
</Grid>
- In the Design view, double-click on MainWindow.
This adds the default window event handler, which is the event handler for the Loaded event. The default generated method call is called Window_Loaded.
- In the code view for MainWindow.xaml.cs, add a call to InitInstance. This call initializes the terminal control with a new host type or a session file.
private void Window_Loaded(object sender, EventArgs e)
{
ibmTerminalControl1.InitInstance(Attachmate.Reflection.UserControl.Wpf.IbmHosts.HostType.IBM3270);
openSystemsTerminalControl1.InitInstance();
}
- If you are using an Open Systems control, add the following using directive:
using Attachmate.Reflection.Emulation.OpenSystems;
- Back in the Design view of the .xaml file, double-click on the control you added (for example, ibmTerminalControl1). This adds the default event handler for the ibmTerminalControl1 TerminalInitializedEvent event. This event is fired after the terminal is initialized from the InitInstance call (made after the window loads).
- In the code view for MainWindow.xaml.cs, add the event handler code as follows. The following code will set the host address and connect to that host.
private void ibmTerminalControl1_TerminalInitializedEvent(object sender, AsyncCompletedEventArgs e)
{
ibmTerminalControl1.IbmTerminal.HostAddress = "yourHostName";
ibmTerminalControl1.IbmTerminal.Connect();
}
private void openSystemsTerminalControl1_TerminalInitializedEvent(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
ITerminal Terminal = openSystemsTerminalControl1.Terminal;
((IConnectingSettingsBestNetwork)Terminal.ConnectionSettings).HostAddress = "yourHostName";
Terminal.Connect();
}
Note: For details on the IbmTerminal object returned from the IbmTerminal control or the Terminal object returned from the OpenSystems control, see the Reflection .NET API Help.
- Build and run the solution. At runtime, you should get a window that renders a terminal host.
Note: If you are developing an application with Visual Studio 2010 that is targeted to the .NET 4.0 framework, you may see the following compiler warning:
Warning A reference was created to embedded interop assembly 'c:\Windows\assembly\ GAC_MSIL\Reflection\15.4.0.0__13bff1b6907eadcf\Reflection.dll' because of an indirect reference to that assembly created by assembly 'c:\Program Files\Attachmate\Reflection\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 Reflection Reference to False. For more about how to resolve this warning, see Technical Note 2579.
|