tags:

views:

276

answers:

1

I work on an application which is extendable using VBScript. I have access to the VB6 form and can add controls and reference other controls on the form. I am also able to launch .Net forms via interop.

What I would like to be able to do is to create a reference to a .Net component and hand it a reference to a VB6 Frame or SSTab and then have the component create an interop user control and place it in the Frame/SSTab. If I use just VBScript to do this I do something like the following:

set frame = Form.Controls("Frame1")
set cmd1 = Form.Controls.Add("vb.commandbutton", "Cmd1")
cmd1.Container = frame
cmd1.Visible = true

I expected to be able to do something similar in the InteropUserControl. There is a property called Container on the interop user control, but it is read only, so I'm not sure how to get the control into a parent container.

Any advice would be appreciated.

Sincerely,

Shane Holder

A: 

Well if you want to know how to add controls dynamically, it is quite simple:

Form.Controls.Add(new MyControl())

If you wanted to get a control into a parent container, that would be the way to do it. It looks like you can not change the parent control on the fly, so you must decide using if/else logic who to add your child control to. Example PseudoCode:

InterOpControl myControl = new InterOpControl();

if (someVariable) {
    Form1.Controls.Add(myControl);
}
else {
    Form2.Controls.Add(myControl);
}

If you can not do this, then you can do:

if (someVariable) {
    Form1.Controls.Add(new InterOpControl());
}
else {
    Form2.Controls.Add(new InterOpControl());
}

Now you don't have a reference to it, but you can simply fetch it later.

Polaris878
That would add it to the form, but not into the specific container in which I want the control displayed.SSTab does not seem to have a .Controls in which to add other controls.Frame does have a .Controls but I'm currently having problems with the interop as Spy++ reports that it is a ThunderRT6Frame and I'm not sure how to get the Interop class generated.
ShaneH