Container control?

Hi.

I'm trying to make a control that can contain other controls. I make a UserControl, but I can't get it to work. I can't drop another control on it.

Sorry for the newbie question, but in VB6 I only had to set a property to make it a container control.

I'm really a bit confused. Any help

Thanks.



Answer this question

Container control?

  • Justin Learning

    ok, :) buy I was talking about design time...


  • JpLindgren

    Just one more thing... this attribute is required for design-time support. Adding controls to other controls at runtime also works without it:

    UserControl11.Controls.Add(Button1)
    ' Set button's position etc...

    Andrej



  • dron747

    Hi,

    to make your control act like a container for other controls at design time, you have to add a special System.ComponentModel.Designer attribute to your control declaration, something like:

    <System.ComponentModel.Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(System.ComponentModel.Design.IDesigner))> _
    Public Class UserControl1
       
    Inherits System.Windows.Forms.UserControl

    End Class

    You can also put this attribute in your control's designer file (UserControl1.Designer.vb)...

    Andrej



  • Marasma

    Sorry guys,

    Doesn't work for me - none of the both methods, Maybe I'm missing something

    Sine RDGS is open source, you can check out the SVN and see yourself. The sources are at: https://svn.sourceforge.net/svnroot/rdgs/windows_x86/.

    A good program for this is TortoiseSVN. Just point it to the above url.

    Thanks. Any help is appreciated.



  • Sai A

    Hi.

    Thank you. I'll try that today when I get home. The first method didn't work for me - I rebuilt the project so I'll try with the second one.


  • wenliang

    Ok, doesn't work....

    Code.....

    <System.ComponentModel.Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(System.ComponentModel.Design.IDesigner))> _

    Public Class ExpandContainerNet

    Inherits System.Windows.Forms.UserControl

    When I drop a control over it at design time it just gets behind it! Thanks for help.



  • Kamen

    Thanks, I'll try that out today night when I get home from work...


  • LarryETL

    Oh my god! I'm feeling like a nOOb. All of your answers worked. The problem I had was that I put a panel into the control, so the other controls couldn't show up.

    Thanks to all who helped.



  • furmangg

    I probably don't know what I'm talking about here, but don't you have to set the parent similar to:

    NumericUpDown1.Parent = TextBox1

    Just throwing out ideas.



  • hazz

    The following is another idea that may work for you.

    You could inherit from the panel control instead of the usercontrol. Maybe you should just try if this works for you.

    Public Class UserControl1
    Inherits
    System.Windows.Forms.Panel

    'Some more coding here

    End Class


  • ryan.rogers

    no, we're talking about design time here. Maybe I forgot something

  • Cesar Francisco

    Hi again,

    so here's the steps to add the Designer attribute... use one of the following  procedures:

    Procedure A

    1. Add new user control to the project and open its code in the editor. You'll see something like

    Public Class UserControl1

    End Class

    2. Delete and replace the above code with the following:

    <System.ComponentModel.Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(System.ComponentModel.Design.IDesigner))> _
    Public Class UserControl1
       
    Inherits System.Windows.Forms.UserControl

    End Class

    3. Rebuild the project and add the control on a form.

    Procedure B

    1. Add new user control to the project. In Solution Explorer, choose Show All Files. Open control's Designer file (UserControl1.Designer.vb). You'll see something like

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Partial Class UserControl1
        Inherits System.Windows.Forms.UserControl

    on the top... 2. Add the Designer attribute to this so it will look like:

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    <System.ComponentModel.Designer(
    "System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(System.ComponentModel.Design.IDesigner))> _
    Partial Class UserControl1
       
    Inherits System.Windows.Forms.UserControl

    3. Rebuild the project and add the control on a form.

    Hope this helps. Let me know how it goes...

    Andrej

    P.S.: it's important to (re)build the project/control for this to work...



  • PedroCGD

    Anyone

    Thanks.



  • Andreas Asterlund

    Can you please send me zipped source package on my mail, please...

    [email removed]

    Andrej



  • Container control?