CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Clone a UserControl

    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

  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: Clone a UserControl

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured