Steps to make a user control
1, create a new project, File New project.
2, add the new item user control. The file type is. cs
Working with user controls
In the user control design industry click on the build item in the toolbar, select the first item to build the solution, or direct point F6;
This user control is displayed at the top of the toolbar of a Windows Form after the build succeeds
Adding controls dynamically
Enter a value of n, click the button, dynamically generate n buttons, and number number
Private voidButton1_Click (Objectsender, EventArgs e) { //first get the user input is a few intCount =Convert.ToInt32 (TextBox1.Text); //empty containers before creatingflowLayoutPanel1.Controls.Clear (); //Loop Create button, then add to container for(inti = 0; I < count; i++) {Button btn=NewButton ();//Instantiate buttonBtn. Text = (i+1). ToString ();//button displays the automatic arranging of this buttonFlowLayoutPanel1.Controls.Add (BTN);//Add this button to the container } }
User controls, dynamically created to add user controls