Click to See Complete Forum and Search --> : Clone a UserControl


John G Duffy
August 11th, 2001, 03:32 PM
How does one go about creating copies of a User Control programatically? I tried this pitiful method to no avail. I am getting Error 711 "Invalid Class string" on the attempt.
My program has two projects (One for Test. The other is the User Control I am trying to clone.

option Explicit
private withevents cmdObject as UserControl

private Sub Command1_Click()
set cmdObject = Form1.Controls.Add("UserControl.UserControl1", "cmdOne")
cmdObject.Visible = true
cmdObject.Caption = "Dynamic Command Button"
cmdObject.Move 1000, 1000, 1000, 1000
End Sub




John G

cksiow
August 11th, 2001, 09:16 PM
the .Add command needs a ProgID which has been registered in the registry as COM component should do. thus "UserControl.UserControl1" probably cannot be found under HKEY_CLASSES_ROOT\, and worst even if it can be found, ProgID is not unique, but only CLSID is unique.

Anyway, this might because of mistype. for instance if you got a project called Project1 which is an activeX control application that got a UserControl1, then it should be like this instead


option Explicit
private withevents cmdObject as Project1.UserControl1

private Sub Command1_Click()
set cmdObject = Form1.Controls.Add("Project1.UserControl1", "cmdOne")
cmdObject.Visible = true
cmdObject.Caption = "Dynamic Command Button"
cmdObject.Move 1000, 1000, 1000, 1000
End Sub




you probably cannot use UserControl with withevents, as VB don't have any type information on that, just like it can't use withevents with Object. I presume, you might want to verify this.




HTH

cksiow
http://vblib.virtualave.net - share our codes