Can anyone give me a good argument one way or another?
I have an 'address' set of fields that are used in various situations (a
client has an address, a destination has an address, etc).
These fields are all normalized into a seperate database table from the
client and destination tables.
My question is, which is better to create, a User Control, or a generic
class that will add controls to a form directly, applying its common event
handlers, etc? Keep in mind, that things such as 'Suite' or 'Apartment
Number' are stored in the client or destination table, since multiple
clients or desitnation 'offices' may be at the same block address (this is
for a geocoding application).
A User Control only seems to be useful if you plan on placing it on a form
with the form designer, however, it seems that you would have to expose all
of the internal control objects anyway if you wanted the outside container
to react to specific events within the control. 9 3332
Hi Richard,
A UserControl, as you say, is a design-time control. If you do not need to
place your AddressControl on a form at design-time I wouldn't use that
approach.
This leaves your create-an-AddressControl class.
However, if the control that is created is always the same (or there's
only a limited set of choices) then you could create an AddressControl which
innherits from the preferred control, eg TextBox, Label.
I couldn't say which would be better without more info.
Regards,
Fergus
Richard,
Generally I would have both.
An Address class that contains the Domain Logic for an Address. Client and
Destination would have an Address Property of type Address.
Then I would have an AddressControl that displays the information found in
the Address class, it would also have an Address Property of type Address.
The form would bind the current objects Address Property to the controls
Address property.
The control itself would bind individual properties of the address object to
the various controls.
Alternatively (additionally?) the AddressControl would have properties that
the form could interact with. It would not expose actual controls. It would
expose new events for any contained controls. Think encapsulation. The fact
that the suite number is a text box today, may change to an updowncontrol
tomorrow.
Public Class AddressControl
Public Event SuiteChanged As EventHandler
Public Event ApartmentNumberChanged As Event Handler
Public Property Suite() As String
Public Property ApartmentNumber() As String
Private WithEvents textSuite As TextBox
Private WithEvents textApartmentNumber As TextBox
End Class
Hope this helps
Jay
"Richard Brown" <rb****@easylift.org> wrote in message
news:uY**************@TK2MSFTNGP09.phx.gbl... Can anyone give me a good argument one way or another?
I have an 'address' set of fields that are used in various situations (a client has an address, a destination has an address, etc). These fields are all normalized into a seperate database table from the client and destination tables.
My question is, which is better to create, a User Control, or a generic class that will add controls to a form directly, applying its common event handlers, etc? Keep in mind, that things such as 'Suite' or 'Apartment Number' are stored in the client or destination table, since multiple clients or desitnation 'offices' may be at the same block address (this is for a geocoding application).
A User Control only seems to be useful if you plan on placing it on a form with the form designer, however, it seems that you would have to expose
all of the internal control objects anyway if you wanted the outside container to react to specific events within the control.
I am actually going to refer to comments in your post and also in Jay's
post.
Well, the address 'control' would actually be made up of several text boxes,
so inheriting from one particular control won't work. But, this 'control
class', would also have an optional map button, if the address is a mapped
address (mailing addresses are not mapped as they could be PO boxes).
For Jay, encapsulation is a good thing... BUT, the suite and apt number text
is actually crossing a slight boundary, since it is not directly related to
the mapped address. (Has to do with roof-top geocoding, only the street
number, street, etc are used). Also, one problem I did leave out, in
several areas, but not all, the first line of the address is also used as a
lookup filter, combined with other fields in passenger or destination. So
that would have to be addressed also, and if other fields are exposed for
lookups, then the exposed methods would have to be changed.
Keep in mind, this is all for internal program use, but I'd like to keep it
as readable and understandable as possible. I'm sure I can come up with a
hundred pieces of functionality to add to the control for various
circumstances, but I have a very large app to write, not just this one
control/implementation.
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:eL**************@tk2msftngp13.phx.gbl... Hi Richard,
A UserControl, as you say, is a design-time control. If you do not
need to place your AddressControl on a form at design-time I wouldn't use that approach.
This leaves your create-an-AddressControl class.
However, if the control that is created is always the same (or there's only a limited set of choices) then you could create an AddressControl
which innherits from the preferred control, eg TextBox, Label.
I couldn't say which would be better without more info.
Regards, Fergus
Hello,
"Fergus Cooney" <fi******@tesco.net> schrieb: A UserControl, as you say, is a design-time control. If you do not need to place your AddressControl on a form at design-time I wouldn't use that approach.
I think it's a big advantage that UserControls are design time controls.
UserControls should be used to create a new control that consists of
multiple controls ("composite control").
Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB.NET http://www.mvps.org/dotnet
Richard, For Jay, encapsulation is a good thing... BUT, the suite and apt number
text is actually crossing a slight boundary, since it is not directly related
to the mapped address. (Has to do with roof-top geocoding, only the street number, street, etc are used). Also, one problem I did leave out, in
So you saying you have 2 (or more) kinds of Addresses. One that includes
Suite & Apt Number and one that does not?
If that is the case I would have an Address object (that does not have Suite
& Apt Number), then I would have a second class derived from this that
includes Suite & Apt number.
I may actually have 3 address objects. AddressBase, MailingAddress &
MappedAddress. Where MailingAddress & MappedAddress inherit from
AddressBase. AddressBase would be an abstract base class (MustInherit),
while MailingAddress & MappedAddress are concrete class (offer full
implementation).
I would probably still have only a single AddressControl that used
AddressBase, AddressBase would be able to indicate when there are extra
'fields' present, such as a 'HasSuite' property. You know a tradeoff between
pure OOP & getting the job done ;-)
Instead of a HasSuite property, I would consider having AddressControl use a
Strategy Pattern (offered from AddressBase) when it is initializing &
displaying the controls, so as to know to show or hide the 'optional map
button', or show or hide the Suite & Apartment controls).
Basically with HasSuite the AddressBase is the strategy, while in the second
I would have a MailingAddressStategy & MappedAddressStategy, I would need a
better idea of the differences between the two address types before I
decided which was better. Of course with Refactoring (www.refactoring.com) I
can change my mind later.
Keep in mind, this is all for internal program use, but I'd like to keep
it as readable and understandable as possible. I'm sure I can come up with a hundred pieces of functionality to add to the control for various circumstances, but I have a very large app to write, not just this one control/implementation.
Which is where I find encapsulation helps. All logic dealing with Address is
in the address object, all logic dealing with displaying an address is in
the AddressControl. All logic unique to MailingAddress is in the
MailingAddress object.
I usually favor strong OOP practices and I find my code is readable &
understandable & Maintainable.
several areas, but not all, the first line of the address is also used as
a lookup filter, combined with other fields in passenger or destination. So that would have to be addressed also, and if other fields are exposed for lookups, then the exposed methods would have to be changed.
I'm not following this: If the form has an Address object, this Address
object is bound to the AddressControl, and the Address.FirstLine is used in
loopups. Why not just use Address.FirstLine instead of
AddressControl.FirstLine?
Hope this helps
Jay
"Richard Brown" <rb****@easylift.org> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... I am actually going to refer to comments in your post and also in Jay's post.
Well, the address 'control' would actually be made up of several text
boxes, so inheriting from one particular control won't work. But, this 'control class', would also have an optional map button, if the address is a mapped address (mailing addresses are not mapped as they could be PO boxes).
For Jay, encapsulation is a good thing... BUT, the suite and apt number
text is actually crossing a slight boundary, since it is not directly related
to the mapped address. (Has to do with roof-top geocoding, only the street number, street, etc are used). Also, one problem I did leave out, in several areas, but not all, the first line of the address is also used as
a lookup filter, combined with other fields in passenger or destination. So that would have to be addressed also, and if other fields are exposed for lookups, then the exposed methods would have to be changed.
Keep in mind, this is all for internal program use, but I'd like to keep
it as readable and understandable as possible. I'm sure I can come up with a hundred pieces of functionality to add to the control for various circumstances, but I have a very large app to write, not just this one control/implementation.
"Fergus Cooney" <fi******@tesco.net> wrote in message news:eL**************@tk2msftngp13.phx.gbl... Hi Richard,
A UserControl, as you say, is a design-time control. If you do not need to place your AddressControl on a form at design-time I wouldn't use that approach.
This leaves your create-an-AddressControl class.
However, if the control that is created is always the same (or
there's only a limited set of choices) then you could create an AddressControl which innherits from the preferred control, eg TextBox, Label.
I couldn't say which would be better without more info.
Regards, Fergus
Thanks for the info, over course, we *all* change our minds sooner or
later....
But, the last part is a little confusing... lookup filter, combined with other fields in passenger or destination.
So that would have to be addressed also, and if other fields are exposed
for lookups, then the exposed methods would have to be changed. I'm not following this: If the form has an Address object, this Address object is bound to the AddressControl, and the Address.FirstLine is used
in loopups. Why not just use Address.FirstLine instead of AddressControl.FirstLine?
Ok, now I'm so confused that I don't remember the question....
Oh yeah... I think I understand what your saying... based on your previous
recommendation of having the address control AND the address class,
basically you are saying encapsulate the UI in the UserControl and
everything else in the Address class. So to perform the lookup
functionality, access the address class that is bound to the UserControl/UI.
Am I on the right track with your thinking?
Richard, recommendation of having the address control AND the address class, basically you are saying encapsulate the UI in the UserControl and everything else in the Address class.
Am I on the right track with your thinking?
Yes
One small note, thinking about it, your UserControl really only needs to
expose the Address property, as the parent control will already have the
object with all the other properties, or you can get the properties off of
the usercontrols' address property...
Hope this helps
Jay
"Richard Brown" <rb****@easylift.org> wrote in message
news:O5*************@TK2MSFTNGP09.phx.gbl... Thanks for the info, over course, we *all* change our minds sooner or later....
But, the last part is a little confusing...
lookup filter, combined with other fields in passenger or destination. So that would have to be addressed also, and if other fields are exposed for lookups, then the exposed methods would have to be changed. I'm not following this: If the form has an Address object, this Address object is bound to the AddressControl, and the Address.FirstLine is used in loopups. Why not just use Address.FirstLine instead of AddressControl.FirstLine?
Ok, now I'm so confused that I don't remember the question.... Oh yeah... I think I understand what your saying... based on your previous recommendation of having the address control AND the address class, basically you are saying encapsulate the UI in the UserControl and everything else in the Address class. So to perform the lookup functionality, access the address class that is bound to the
UserControl/UI. Am I on the right track with your thinking?
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.
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... Richard, Generally I would have both.
An Address class that contains the Domain Logic for an Address. Client and Destination would have an Address Property of type Address.
Then I would have an AddressControl that displays the information found in the Address class, it would also have an Address Property of type Address.
The form would bind the current objects Address Property to the controls Address property.
The control itself would bind individual properties of the address object
to the various controls.
Alternatively (additionally?) the AddressControl would have properties
that the form could interact with. It would not expose actual controls. It
would expose new events for any contained controls. Think encapsulation. The
fact that the suite number is a text box today, may change to an updowncontrol tomorrow.
Public Class AddressControl
Public Event SuiteChanged As EventHandler Public Event ApartmentNumberChanged As Event Handler
Public Property Suite() As String
Public Property ApartmentNumber() As String
Private WithEvents textSuite As TextBox Private WithEvents textApartmentNumber As TextBox
End Class
Hope this helps Jay
"Richard Brown" <rb****@easylift.org> wrote in message news:uY**************@TK2MSFTNGP09.phx.gbl... Can anyone give me a good argument one way or another?
I have an 'address' set of fields that are used in various situations (a client has an address, a destination has an address, etc). These fields are all normalized into a seperate database table from the client and destination tables.
My question is, which is better to create, a User Control, or a generic class that will add controls to a form directly, applying its common
event handlers, etc? Keep in mind, that things such as 'Suite' or 'Apartment Number' are stored in the client or destination table, since multiple clients or desitnation 'offices' may be at the same block address (this
is for a geocoding application).
A User Control only seems to be useful if you plan on placing it on a
form with the form designer, however, it seems that you would have to expose all of the internal control objects anyway if you wanted the outside
container to react to specific events within the control.
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/de...eaworapps2.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" <rb****@easylift.org> wrote in message
news:eX*************@TK2MSFTNGP11.phx.gbl... 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>> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DraguVaso |
last post by:
Hi,
I'm having some weird behaviour, and I can't find any solution to this.
I made a UserControl (uclCommands) which contains a Toolbar (ToolBar1) with
Modifiers = Public.
I put this...
|
by: jralford |
last post by:
Hi,
Another question from a C# newbie:
I have a usercontrol class that includes a customized control.
Now, if I create an instance of the class, and click on it, a click
event is raised for the...
|
by: N. Demos |
last post by:
Hello,
I have a custom usercontrol, of which I have two instances of in my aspx
page. Both the usercontrol and page have codebehind. In the page
codebehind, I want a member variable for each...
|
by: Crirus |
last post by:
I need to derive the Windows.Forms.Control 2 times so I design a class like
this
Public Class BMControl
Inherits System.Windows.Forms.UserControl
Public Class MapControl
Inherits BMControl
|
by: sotto |
last post by:
Hi,
how can i make a usercontrol that inherits from the
system.windows.forms.button instead of the forms.usercontrol ?
I want to add a fiew features to my button and still be able to drag it...
| |
by: Michael Maes |
last post by:
Hi,
I have a UserControl with some "Children" (e.g. one ComboBox & one Label).
I add the UserControl on a Form.
If I perform a recursive scan through that Form's Control-Collection the...
|
by: JohnR |
last post by:
In it's simplest form, assume that I have created a usercontrol,
WSToolBarButton that contains a button. I would like to eventually create
copies of WSToolBarButton dynamically at run time based...
|
by: Joe |
last post by:
Hello All:
Do I have to use the LoadControl method of the Page to load a UserControl?
I have a class which contains three methods (one public and two private).
The class acts as a control...
|
by: Joe |
last post by:
Is it possible to inherit from a UserControl? If I try my user control
class is not recognized.
Thanks,
Joe
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |