Domanda

ı 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.

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

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

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top