3

ı have been serching this for a while but I couldn't come up with a conclusion. What is UserControl? For me we can do everything with creating new windows forms instead of User Control. I know there is a reason to use but it is not clear right now. If someone illuminates the mystery that would be great.

Zgrkpnr
  • 1,191
  • 4
  • 15
  • 32
  • 1
    You can create a custom control with UserControl. Imagine this, you want to create a panel with some button, textboxes, comboboxes in it. Every control in this panel has some methods like keypress, textchanged ... And youre gonna use this panel more than once. You put this panel in a UserControl , write the methods inside this control and whenever you need it just drag and drop it to your project and youre good to go. – Batu.Khan Apr 02 '14 at 13:34

4 Answers4

3

A user control is basically a grouping of other existing control, intended as a reusable component (i.e. composite control). If you need to place the same group of controls on different windows you'd rather group them in a user control, adding things like data validation for instance, and then reuse this control whenever you need it.

Here is some more reading.

Marius Bancila
  • 16,053
  • 9
  • 49
  • 91
2

UserControls allow you to reuse your code. For example if you need a small component that displays two values (code and description), with UserControls you can design it only one time and then reuse it in other forms.

Also, you can add your custom properties\methods to the UserControl; in this way you can define simple (or even more complex) functions associated to the GUI control.

Hope this helps.

1

imagine you have a GridView with some new methods you create, and which you want to use on several pages. There you go. A UserControl is useful. That's just one example

Ricardo Appleton
  • 679
  • 10
  • 22
0

As the others have explained a UserControl groups 'real' Controls and the logic that makes them work together as one component.

Imagine an application where the user can decide wether it runs in MDI mode or with separate windows or with tabbed pages. You can add the UCs of your application to any of these easily.

Think of a MP3 player with various controls, buttons, labels and sliders and user drawn-gauges. If it's in a UC you can re-use it directly. If it is all on a window, how do you re-use it?

So UCs are about flexibilty and re-using visual components.

TaW
  • 53,122
  • 8
  • 69
  • 111