Create a Window Forms application with the use of Common controls

1. First, create a new Windows Forms application project in Visual Studio. Go to File > New > Project and select “Windows Forms App (.NET Framework)”.

2. In the Solution Explorer, right-click on the project name and select “Add > User Control”. Name the control “MyUserControl”.

3. Open the “MyUserControl.cs” file and add the following code to create a label and a button control:

				
					using System.Windows.Forms;

public partial class MyUserControl : UserControl
{
    public MyUserControl()
    {
        InitializeComponent();
    }

    private void MyUserControl_Load(object sender, EventArgs e)
    {
        Label label1 = new Label();
        label1.Text = "Hello, world!";
        label1.Location = new Point(10, 10);
        this.Controls.Add(label1);

        Button button1 = new Button();
        button1.Text = "Click me!";
        button1.Location = new Point(10, 40);
        this.Controls.Add(button1);
    }
}

				
			

4. Open the main form (“Form1.cs”) and add the following code to create an instance of the user control and add it to the form

				
					using System.Windows.Forms;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        MyUserControl myUserControl1 = new MyUserControl();
        myUserControl1.Location = new Point(10, 10);
        this.Controls.Add(myUserControl1);
    }
}

				
			

5. Build and run the application to see the label and button controls displayed in the user control, which is added to the main form

				
					SELECT AVG(emp_sal)
FROM employee;
				
			
				
					SELECT COUNT(*)
FROM employee;