INetControlBox.CreateControl

Syntax

CreateControl(Type: IForeNETRuntimeType): Boolean;

Parameters

Type is a type containing description of the .NET component to be created.

Description

The CreateControl method creates .NET component by the type description passed by the Type parameter and displays it in the NetControlBox component.

Example

Executing this example requires a form with the Button1 button, and two NetControlBox components named NetControlBox1 and NetControlBox2.

Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
    Run: IForeNETRuntime;
    AsmSys: String;
    Asm: IForeNETRuntimeAssembly;
    Type1, Type2: IForeNETRuntimeType;
Begin
    Run := ForeNETAssemblyClass.Runtime;
    AsmSys := "Microsoft.VisualBasic.Compatibility, Version=7.0.5000.0, Culture=Neutral,PublicKeyToken=b03f5f7f11d50a3a";
    Asm := Run.SystemAssembly(AsmSys);
    //Creating DirListBox in first NetControlBox
    Type1 := Asm.Type("Microsoft.VisualBasic.Compatibility.VB6.DirListBox");
    NetControlBox1.CreateControl(Type1);
    NetControlBox1.AttachHandler("DoubleClick");
    //Creating FileListBox in second NetControlBox
    Type2 := Asm.Type("Microsoft.VisualBasic.Compatibility.VB6.FileListBox");
    NetControlBox2.CreateControl(Type2);
End Sub Button1OnClick;

Sub NetControlBox1OnEvent(Sender: Object; Args: INetControlBoxEventArgs);
Var
    Run: IForeNETRuntime;
    AsmSys: IForeNETRuntimeAssembly;
    Instance1, Instance2: IForeNETRuntimeObjectInstance;
    Type1, Type2: IForeNETRuntimeType;
    Binding: IForeNETRuntimeMethodBinding;
    Method: IForeNETRuntimeMethod;
    Args1: IForeNETRuntimeMethodArgs;
    s: String;
Begin
    If Args.EventName = "DoubleClick" Then
        //Get  the path, selected in DirListBox
        Run := ForeNETAssemblyClass.Runtime;
        Instance1 := NetControlBox1.Control;
        Type1 := Instance1.GetType;
        Method := Type1.Method("get_Path");
        s := Run.ObjectToVariant(Method.Invoke(Instance1));
        //Set path to FileListBox to view files in this folder
        //Library for work with types of data
        AsmSys := Run.SystemAssembly("mscorlib, PublicKeyToken=b77a5c561934e089");
        Instance2 := NetControlBox2.Control;
        Type2 := Instance2.GetType;
        Binding := Type2.Assembly.Runtime.CreateBinding(1);
        Binding.Types.Item(0) := AsmSys.Type("System.String");
        Method := Type2.Method("set_Path", Binding);
        Args1 := Method.CreateArgs;
        Args1.Value(0) := s;
        Method.Invoke(Instance2, Args1);
    End If;
End Sub NetControlBox1OnEvent;

After executing the example, clicking the button in the NetControlBox1 and NetControlBox2 components creates the .NET components DirListBox and FileListBox, used to select the folder in the disc and view folder contents, accordingly. The monitoring of the DoubleClick event is enabled for the DirListBox component. On handling the event, the path selected in the DirListBox component is set for the FileListBox component.

See also:

INetControlBox