hi,
Anyone can give a detail or information about user control in C#. About its purpose, when its the right time to use that class?
thnks in advance,
Popskie
Printable View
hi,
Anyone can give a detail or information about user control in C#. About its purpose, when its the right time to use that class?
thnks in advance,
Popskie
UserControl is a class you must inherit. It should be used when no control or combination of controls will do what you want. There are examples in the Codebank of user controls.
Typically though, as I have had spanked into me many times on these forums, it's not necessary to reinvent the wheel. Look at what's available, and if you have a set purpose in mind you cannot fulfill with the frameworks controls, you make a user control.
Bill
A UserControl is generally just a way to group existing controls into a single unit that can be reused and can hide some of the lower-level functionality behind public members of the control itself. If you want genuinely new functionality then you would normally inherit an existing control and override existing members or add new ones. These are not hard and fast rules of course, but in my experience this is the way it happens in the bulk of circumstances.
An example would be if you want a textbox to allow only numeric inputs that fall below 666, and if you use this control all over your project. That'd warrant the creation of a user contorl.
For that wouldn't it be easier to derive the new control from the Textbox, rather than creating a new one?Quote:
Originally Posted by mendhak
Yes, and obviously I did not think my answer very well before posting it. Thanks for pointing it out.
You always do this to me. :cry: