Subforms question

lion8420

Member
Joined
Sep 11, 2012
Messages
11
Programming Experience
1-3
Hello

First off I am a novice programmer. I am currently working on an application in VS2012. My quesion is I plan on using 2 subforms on my main form. These forms are inside a split container. I am mainly using them as a design tool so that I can create many versions of the forms and only display the ones that I need at a given time. I have built a few already and everything is working fine as far as I can tell. My concern is that I will be running into some kind of problem in the future because of this design stratagy.

The forms are transparent to the user. They are borderless and just appear as part of the main form.

Any guidance would be appreciated.

ML
 
That is a bad idea. If you don't actually want a form to act as a form then don't use a form. If you want to place something inside a SplitContainer then you should be using a control, not a form. If you want the same design experience as you get with forms then you should be creating a UserControl. You design a UserControl in basically the same way as you do a form, adding child controls and code. Once compiled, you can use the UserControl in the same way you do any other control, i.e. add it to a form in the designer or create it and add it to the form in code.
 
That is a bad idea. If you don't actually want a form to act as a form then don't use a form. If you want to place something inside a SplitContainer then you should be using a control, not a form. If you want the same design experience as you get with forms then you should be creating a UserControl. You design a UserControl in basically the same way as you do a form, adding child controls and code. Once compiled, you can use the UserControl in the same way you do any other control, i.e. add it to a form in the designer or create it and add it to the form in code.


Thank you for the guidance. I have never used a user control. Is there anything I should know?

I messed around with it just now. I added a user control to a splitcontainer by creating a usercontrol variable and adding it to the control. I then interact with the usercontrol by

usercontrol = splitcontainer.panel2.controls("usercontrol")

then

usercontrol.textbox.text = "test"

is that the accepted way of interacting with the controls?

Thanks
 
It's a control and it works like any other control. The one thing that I would point out is that, just like a form, while it is possible to simply add child controls and access them directly, that is not good practice. All child controls should be declared Private (default is Public) and then, from the outside, code can only interact with the UC itself via its properties, methods and events, with no direct access to the child controls. If you want to be able to set the Text of a TextBox on the UC in code then you should add a property to the UC that will internally get and set the TextBox property, e.g.
Public Property TextBox1Text() As String
    Get
        Return TextBox1.Text
    End Get
    Set(value As String)
        TextBox1.Text = value
    End Set
End Property
You would, of course, use more appropriate names but that would be the pattern.
 
Back
Top