Richard,
Ok, say you have a number of fields that make up a 'form'.
Ok, those fields could be used in an MDI child, or they can be used in a tab
page, or they can be used in a modal dialog.
Now, should I make that passenger data entry screen a form, a user control
or a class that spits out controls?
I would make the passenger data entry 'screen' either a form or a user
control. If I needed it 'hosted' in different containers (form, tab page,
MDI child, modal dialog) I would lean toward user control. As the user
control can be placed any of them.
If I made the Passenger Data Entry a user control, I would consider
inheriting from a custom UserControl class, or implement a specific
interface, such that the Data Entry Control would allow letting its
container know what tool bar buttons, menu items, caption should be used in
the enclosing 'frame' (frame here is Window/Form not necessarily GroupBox)
The above is partially explained in:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html/reaworapps2.asp
I saw partially as you can go much further than the article takes you.
I dont *think* you can nest UserControls inside UserControls (code wise, not
container wise),
The code for a user control is 'part' of that user control.
You can place user controls on user controls on user controls. In other
words user controls can be containers for other user controls.
Within your source you can have one user control nested inside another,
however I would not do that, especially here. You loose designer support,
and you are not gaining anything that I can tell. I normally only nest class
definition when the nested class is an implementation detail for the outer
class (the Node class for a LinkedList class that holds the data & link info
for each element in the LinkedList).
This is valid VB.NET:
Public Class UC1
Inherits System.Windows.Forms.UserControl
Public Class UC2
Inherits System.Windows.Forms.UserControl
' other stuff omitted.
End Class
' other stuff omitted.
End Class
For the project I am currently working on. I have a handful of user
controls, that are placed a couple of other user controls, these two user
controls are placed on a third, this third is placed on a tab page. So I
have something like:
Form
TabControl
TabPage
UC1
UC2
ExGroupBox
UC4
UC5
ExGroupBox
UC6
UC6
UC3
ExGroupBox
UC7
UC8
TabPage
UC1
UC2
ExGroupBox
UC4
UC5
ExGroupBox
UC6
UC6
UC3
ExGroupBox
UC7
UC8
Remember Encapsulation, all the logic for UC7 is in UC7, it is not co
mingled in code with UC8, ExGroupBox & UC3. Of course UC3 has code that
interacts with UC7 & UC8, but it is not UC7 or UC8 specific code, it is UC3
code.
In case you were wondering ExGroupBox derives from GroupBox and overrides
the OnLayout event to do some custom arranging of the contained controls. In
the above I use it like a standard GroupBox, not a user control.
so wouldn't the control 'spitting' (I like that term for
Having an object that 'spits' out other objects is a Builder Pattern (of
sorts), and yes that is always an option, however I suspect it will be more
work, without any real gain. The problem as I see it where are you event
handlers, are they co mingled with something else (introducing coupling and
losing cohesion).
controls to a blank form, or to a tab page, or to an MDI child and still
have the class handle it all for you.
Remember a UserControl can be placed (dynamically (aka spit out)) onto a
blank form, a tab page, a MDI child, another User Control, any other
container control). Also the code for the UserControl is encapsulated within
that user control.
Hope this helps
Jay
Richard Brown said:
Ah ha! I remember the main reason I was having to figure this out....
Ok, say you have a number of fields that make up a 'form'.
Ok, those fields could be used in an MDI child, or they can be used in a tab
page, or they can be used in a modal dialog.
So, for example, I have a passenger data entry screen, with the Address
UserControl we've talked about.
Now, should I make that passenger data entry screen a form, a user control
or a class that spits out controls?
I dont *think* you can nest UserControls inside UserControls (code wise, not
container wise), so wouldn't the control 'spitting' (I like that term for
some reason, pardon me) be a better approach? That way, you could 'spit'
controls to a blank form, or to a tab page, or to an MDI child and still
have the class handle it all for you.
<<snip>>