Sie sind auf Seite 1von 5

17FOTCA11003

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();
}

private void button1_Click(object sender, EventArgs e)


{
MessageBox.Show("Welcome to First Windows Application");
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}

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();
}

private void button1_Click(object sender, EventArgs e)


{
MessageBox.Show(""+label1.Text+": "+textBox1.Text+"\n"
+ label2.Text + ": " + textBox2.Text + "\n"
+ label3.Text + ": " + textBox3.Text + "\n");
}
}
}

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);
}

private void groupBox2_Enter(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{
if (radioButton1.Checked)
{
this.BackColor = System.Drawing.Color.Red;
}
else if (radioButton2.Checked)
{
this.BackColor = System.Drawing.Color.Green;
}
else if (radioButton3.Checked)
{
this.BackColor = System.Drawing.Color.Blue;
}
if (radioButton4.Checked)
{
this.ForeColor = System.Drawing.Color.Black;
}
else if (radioButton5.Checked)
{
this.ForeColor = System.Drawing.Color.White;
}

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();
}

private void Form1_Load(object sender, EventArgs e)


{
label3.Text = "";
}

private void button1_Click(object sender, EventArgs e)


{
if (radioButton1.Checked)
{
int n1 = Convert.ToInt32(textBox1.Text);

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

Das könnte Ihnen auch gefallen