Reflection .NET API
Attachmate.Reflection.Framework Assembly / Attachmate.Reflection.Framework Namespace / MyReflection Class / GetControlsByName Method
The name of the control. To get all unnamed controls, use an empty string.
Example


In This Topic
    GetControlsByName Method (MyReflection)
    In This Topic
    Gets the controls that match the specified control name in all instances of Reflection.
    Syntax
    'Declaration
     
    
    Public Shared Function GetControlsByName( _
       ByVal name As String _
    ) As Object()
    'Usage
     
    
    Dim name As String
    Dim value() As Object
     
    value = MyReflection.GetControlsByName(name)
    public static object[] GetControlsByName( 
       string name
    )

    Parameters

    name
    The name of the control. To get all unnamed controls, use an empty string.

    Return Value

    An array of controls that match the specified control name. If an empty string is passed as the name, an array of unnamed controls is returned.
    Example
    This sample shows how to get all of the unnamed controls in an instance of Reflection and then find specific controls.
    //This sample gets all of the unnamed terminal controls running in an instance of Reflection.
    //Before you run this sample, make sure at least one session is running in a Reflection workspace. 
    //If more than one instance of Reflection is running, the session must be running in the first instance that was started.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Attachmate.Reflection.Framework;
    using Attachmate.Reflection.Emulation.IbmHosts;
    using Attachmate.Reflection.Emulation.OpenSystems;
    
    namespace ConnectToASession
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Get a handle to the first Application instance started manually.
                //For production code, use a try catch block here to handle a System Application Exception thrown
                //if the app isn't running.
                Application app = MyReflection.ActiveApplication;
    
                //Get all of the terminal controls that are not named
                object[] terminals = app.GetControlsByName("");
    
                //Check to make sure at least one session is running.
                if (terminals != null && terminals.Length > 0)
                {
                    
                    //Find terminals based on terminal type and host address
                    foreach (Object terminal in terminals)
                    {
    
                        if (terminal.ToString().Contains("Ibm")) 
                        {
                            IIbmTerminal terminalIBM = (IIbmTerminal)terminal;
    
                            //Find specific terminals based on host address
                            //Then get connection status, get text from the screen, or perform other tasks
                            Console.WriteLine(terminalIBM.HostAddress);
    
    
                        }
    
                        if (terminal.ToString().Contains("OpenSystems"))
                        {
                            ITerminal terminalOS = (ITerminal)terminal;
    
                            IConnectionSettingsTelnet conn = terminalOS.ConnectionSettings as IConnectionSettingsTelnet;
    
                            if (conn != null)
                            {
                                Console.WriteLine(((terminalOS.ConnectionSettings as IConnectionSettingsTelnet).HostAddress));
                            }
                          
                        }
                    
                    }
    
                }
                Console.ReadLine();
    
            }
        }
    }
    
    
    See Also