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.
- private static Addition _instance;
- public static Addition instance {
- get {
- if (_instance == null) _instance = new Addition();
- return _instance;
- }
- }
Step 4
Call that instance in your form on button click.
- private void Add_Click(object sender, EventArgs e) {
- panel1.Visible = true;
- panel1.Controls.Add(Addition.instance);
- Addition.instance.Dock = DockStyle.Fill;
- Addition.instance.BringToFront();
- }
Step 5
Similarly, do it for subtraction
Now, rebuild your project.
Hence your Windows Form is ready with addition and subtraction user controls.