50% found this document useful (2 votes)
444 views

C# Tutorial

1. The document describes 4 tutorials for creating Windows forms applications in C# that demonstrate different form functionality: - Tutorial 1 creates a form with buttons to display a message or close the form - Tutorial 2 creates a form to display a combined message based on user input textboxes - Tutorial 3 creates a form where selecting different radio buttons changes the form's background and text colors - Tutorial 4 creates a form to perform basic math operations like addition on two user-entered numbers and display the result 2. For each tutorial, the document provides the code to create the form and handle the desired button click events to trigger the intended functionality. 3. Screenshots are included showing example outputs of each completed tutorial form.

Uploaded by

Krutik Barvaliya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
444 views

C# Tutorial

1. The document describes 4 tutorials for creating Windows forms applications in C# that demonstrate different form functionality: - Tutorial 1 creates a form with buttons to display a message or close the form - Tutorial 2 creates a form to display a combined message based on user input textboxes - Tutorial 3 creates a form where selecting different radio buttons changes the form's background and text colors - Tutorial 4 creates a form to perform basic math operations like addition on two user-entered numbers and display the result 2. For each tutorial, the document provides the code to create the form and handle the desired button click events to trigger the intended functionality. 3. Screenshots are included showing example outputs of each completed tutorial form.

Uploaded by

Krutik Barvaliya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like