Why do we use UserControl?

后端 未结 4 2017
予麋鹿
予麋鹿 2020-12-19 18:53

ı 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

相关标签:
4条回答
  • 2020-12-19 19:13

    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

    0 讨论(0)
  • 2020-12-19 19:14

    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.

    0 讨论(0)
  • 2020-12-19 19:15

    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.

    0 讨论(0)
  • 2020-12-19 19:25

    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.

    0 讨论(0)
提交回复
热议问题