How To Add User Controls For Addition And Subtraction In Windows.Forms

This blog is about how to add more than one user control on single panel on button click.

Let us learn how to create a Windows.Forms application for addition and subtraction.
 
Step 1
 
Create a new Windows.Forms project. 

Add a form into the project.

Add panel and buttons for addition and subtraction.


Step 2

Create user controls for addition.

 

Step 3

Create an instance of user control in its cs file.
  1. private static Addition _instance;  
  2. public static Addition instance {  
  3.     get {  
  4.         if (_instance == null) _instance = new Addition();  
  5.         return _instance;  
  6.     }  
  7. }  
Step 4

Call that instance in your form on button click.
  1. private void Add_Click(object sender, EventArgs e) {  
  2.     panel1.Visible = true;  
  3.     panel1.Controls.Add(Addition.instance);  
  4.     Addition.instance.Dock = DockStyle.Fill;  
  5.     Addition.instance.BringToFront();  
  6. }  
Step 5

Similarly, do it for subtraction

Now, rebuild your project.
 
Hence your Windows Form is ready with addition and subtraction user controls.