C# Tutorial
C# Tutorial
BCA (Sem-5)
Tutorial-5
1: Design a Form like below. When user Click on OK Button it will print “Welcome to First
Windows Application” on Label. When User Click on Cancel button form get closed.
Code:
using System;
using System.Windows.Forms;
namespace Tutorial_5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Output:
1
CE-IT-BCA-MCA
17FOTCA11003
BCA (Sem-5)
2 : Design a Form like below. When user click on Send Message Button it will display
combine message like below on label:“Message of <<Name>> from <<Organization>> with
<<comment>>”
Code:
using System;
using System.Windows.Forms;
namespace Tutorial_5_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Output:
2
CE-IT-BCA-MCA
17FOTCA11003
BCA (Sem-5)
3 : Design a form like below. Depends on User’s selection, Background color and ForeColor of
Form will change
Code:
using System;
using System.Windows.Forms
namespace Tutorial_5_3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
radioButton1.CheckedChanged += new EventHandler(Form1_Load);
radioButton2.CheckedChanged += new EventHandler(Form1_Load);
radioButton3.CheckedChanged += new EventHandler(Form1_Load);
radioButton4.CheckedChanged += new EventHandler(Form1_Load);
radioButton5.CheckedChanged += new EventHandler(Form1_Load);
radioButton6.CheckedChanged += new EventHandler(Form1_Load);
}
3
CE-IT-BCA-MCA
17FOTCA11003
BCA (Sem-5)
else if (radioButton6.Checked)
{
this.ForeColor = System.Drawing.Color.Red;
}
}
}
}
Output:
4 : Design a form like below. When user click on Answer button, selected operation
performed on given two numbers and answer is displayed on as shown.
Code:
using System;
using System.Windows.Forms;
namespace Tutorial_5_4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
4
CE-IT-BCA-MCA
17FOTCA11003
BCA (Sem-5)
int n2 = Convert.ToInt32(textBox2.Text);
double n = n1 + n2;
label3.Text = n1 + " and " + n2 + " Adition is " + n;
}
else if (radioButton2.Checked)
{
int n1 = Convert.ToInt32(textBox1.Text);
int n2 = Convert.ToInt32(textBox2.Text);
double n = n1 - n2;
label3.Text = n1 + " and " + n2 + " Substraction is " + n;
}
if (radioButton3.Checked)
{
int n1 = Convert.ToInt32(textBox1.Text);
int n2 = Convert.ToInt32(textBox2.Text);
double n = n1 * n2;
label3.Text = n1 + " and " + n2 + " Multiplication is " + n;
}
if (radioButton4.Checked)
{
int n1 = Convert.ToInt32(textBox1.Text);
int n2 = Convert.ToInt32(textBox2.Text);
double n = n1 / n2;
label3.Text = n1 + " and " + n2 + " Division is " + n;
}
}
}
}
Output:
5
CE-IT-BCA-MCA