Welcome to FoxLearn
Today we will learn how to load user control dynamically
User controls provide a means by which custom graphical interfaces can be created and reused
A user control is essentially a component with a visual representation
As such, it might consist of one or more Windows Forms controls, components, or blocks of code that can extend functionality by validating user input, modifying display properties, or performing other tasks required by the user
User controls can be placed on Windows Forms in the same manner as other controls
The UserControl gives you the ability to create controls that can be used in multiple places within an application or organization
You can include all the code needed for validation of common data you ask the user to input
Some examples of this are e-mail addresses, telephone numbers, and postal codes
Another efficient use of the user control, is to simply preload a ComboBox or ListBox, with static items you commonly use in almost every application
Some examples of this are countries/regions, cities, states, and office locations
Now, we will use singleton pattern to create an instance of the user control
A Singleton is the combination of two essential properties, ensure a class has only one instance and provide a global point of access to it
Often, a system only needs to create one instance of a class, and that instance will be accessed throughout the program
Examples would include objects needed for logging, communication, database access, etc
So, if a system only needs one instance of a class, and that instance needs to be accessible in many different parts of a system, one control both instantiation and access by making that class a singleton
Now, we will add user control to panel
Windows Forms Panel controls are used to provide an identifiable grouping for other controls
Typically, you use panels to subdivide a form by function
For example, you may have an order form that specifies mailing options such as which overnight carrier to use
Grouping all options in a panel gives the user a logical visual cue
At design time all the controls can be moved easily when you move the Panel control, all its contained controls move, too
The controls grouped in a panel can be accessed through its Controls property
The Panel control is similar to the GroupBox control
However, only the Panel control can have scroll bars, and only the GroupBox control displays a caption
Now, we will add some controls to play the demo
Thank you for watching this video