IT-412 Final
IT-412 Final
namespace WindowsFormsApp17
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Program 2:
Write a program that displays a list box to display a list box to display a list of pictures and
a group box with different options for picture size. The user can click any picture in the list
box and size from group box to display the selected picture in the desired size in the picture
box
namespace list
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
listBox1.Items.Add("Pakistan");
listBox1.Items.Add("Turkey");
listBox1.Items.Add("Dubai");
listBox1.Items.Add("Japan");
listBox1.Items.Add("South Korea");
listBox1.Items.Add("Bangladesh");
}
private void button5_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string select = listBox1.SelectedItem.ToString();
switch(select)
{
case "Pakistan":
pictureBox1.Image = Properties.Resources.pak;
break;
case "Turkey":
pictureBox1.Image = Properties.Resources.Turkey;
break;
case "Dubai":
pictureBox1.Image = Properties.Resources.Dubai;
break;
case "Japan":
pictureBox1.Image = Properties.Resources.Japan;
break;
case "South Korea":
pictureBox1.Image = Properties.Resources.South_korea;
break;
case "Bangladesh":
pictureBox1.Image = Properties.Resources.hero_bangladesh;
break;
}
}
private void rb1_CheckedChanged(object sender, EventArgs e)
{
if (rb1.Checked == true)
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
}
private void rb2_CheckedChanged(object sender, EventArgs e)
{
if (rb2.Checked == true)
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
private void rb3_CheckedChanged(object sender, EventArgs e)
{
if (rb3.Checked == true)
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
private void rb4_CheckedChanged(object sender, EventArgs e)
{
if (rb4.Checked == true)
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
Program 3:
Write a program that gets your age in years in text box and displays the age in days and
month
namespace Age
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
namespace radio
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Program 6:
In a given program three buttons and 1 label have been created, when you click on
Button1 label display a caption Hello CS, when click on show (Button 2) label show a
caption Focus on programming, when click on Clear (Button 3) label should disappear from
the screen.
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "Hello CS";
}
Program 7: The following program displays two buttons on Form. The caption of the
buttons changes to “GOTFOCUS” and “LOST FOCUS” when a specific event occurs.
private void button1_Click(object sender, EventArgs e)
{
Program 8: Write a program that concatenate the values of two text boxes and display in
the third text Box
CS-412 Program 9:
Write a program that stores two values in two integer variables and perform all arithmetic
operations on them and Display the result.
namespace math
{
public partial class Form1 : Form
{
string num1, num2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
num1 = textBox1.Text;
num2 = textBox2.Text;
if(num1==""&&num2=="")
{
MessageBox.Show("Enter Number in Textboxes");
return;
}
int n1 = int.Parse(num1);
int n2 = int.Parse(num2);
int op = n1 + n2;
MessageBox.Show($"Answer :{op}","Operation");
}
private void button2_Click(object sender, EventArgs e)
{
num1 = textBox1.Text;
num2 = textBox2.Text;
if (num1 == "" && num2 == "")
{
MessageBox.Show("Enter Number in Textboxes");
return;
}
int n1 = int.Parse(num1); int n2 = int.Parse(num2);
int op = n1 - n2;
MessageBox.Show($"Answer :{op}", "Operation");
}
private void button3_Click(object sender, EventArgs e)
{
num1 = textBox1.Text;
num2 = textBox2.Text;
if (num1 == "" && num2 == "")
{
MessageBox.Show("Enter Number in Textboxes");
return;
}
int n1 = int.Parse(num1); int n2 = int.Parse(num2);
int op = n1 * n2;
MessageBox.Show($"Answer :{op}", "Operation");
}
private void button4_Click(object sender, EventArgs e)
{
num1 = textBox1.Text;
num2 = textBox2.Text;
if (num1 == "" && num2 == "")
{
MessageBox.Show("Enter Number in Textboxes");
return;
}
int n1 = int.Parse(num1); int n2 = int.Parse(num2);
int op = n1 / n2;
MessageBox.Show($"Answer :{op}", "Operation");
}
private void button5_Click(object sender, EventArgs e)
{
num1 = textBox1.Text;
num2 = textBox2.Text;
if (num1 == "" && num2 == "")
{
MessageBox.Show("Enter Number in Textboxes");
return;
}
int n1 = int.Parse(num1); int n2 = int.Parse(num2);
int op = (int)Math.Pow(n1,n2);
MessageBox.Show($"Answer is :{op}", "Operation");
}
private void button6_Click(object sender, EventArgs e)
{
num1 = textBox1.Text;
num2 = textBox2.Text;
if (num1 == "" && num2 == "")
{
MessageBox.Show("Enter Number in Textboxes");
return;
}
int n1 = int.Parse(num1); int n2 = int.Parse(num2);
int op = n1 % n2;
MessageBox.Show($"Answer is :{op}", "Operation");
} }}
Program 10:
Write a program to enter an hour’s(3000)in text box, when you compute it, it shows the output
in message box in weeks, days and hours
Program 13:
login page with database
private void login_Click(object sender, EventArgs e)
{
//Login Button
string user = textBox1.Text; // admin
string pass = textBox2.Text; //123
//connection string, database name reg
SqlConnection con= new SqlConnection(@"DataSource=DESKTOP-E5FM6G9\SQLEXPRESS
;Initial Catalog=reg;Integrated Security=True");
con.Open();
string query = $"SELECT * FROM users WHERE email='{user}' AND password='{pass}' ";
// users is table name
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
MessageBox.Show("Login Successfully");
}
else
{
MessageBox.Show("invalid email or password");
return;
}
}