Steps to develop a composite control using UserControl
- Right click on the project.
- Choose Add new item.
- Select UserControl.
- Then, drag the necessary controls from the common control section into the UserControl that you have just added.
- Start writing some codes for this new UserControl. Of course, the most important will be loading data, validating user input and saving data. Another piece of code that is helpful is called "RefreshUI" which is responsible for controlling what should be hide or show on the screen base on the parent form/control. You might consider to add this method into your UserControl.
From my experience, it seems many developers especially fresh graduate they "know" UserControl but "never use" it. Below is some example from live experience:
- My customer asked me to develop an attendance grid which displays all the check-in guests. So, I started with "attendance item" control which displays the guest's photo + name. Then, I developed another control call "attendance grid". Finally, I developed "attendance" control which relies on both attendance item and attendance grid.
- The situation gets complicated when you have domestic guests and international guests. These guests are using different "identity card" and the identity number are handled in different way. So, we develop a UserControl which is able to capture both domestic and international identity number. This control is then reused in many of the screens.
- We also develop a composite control to show the necessary options for the user for generating report.
- Application menu is the composite control that will be reused in all projects.
No comments:
Post a Comment