You are on page 1of 7

FAIQA MEHBOOB(032)

BSE IV-B
FJWU
LAB:08
Objective:List Box,Combo Box
Task # 01
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace lab81
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (this.textBox1.Text != "")
{ listBox1.Items.Add(this.textBox1.Text); }
else
{
MessageBox.Show("please insert atleast one iteam");
}
}

private void button2_Click(object sender, EventArgs e)


{

if (this.listBox1.SelectedIndex >= 0)
{ this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex); }
}

private void button3_Click(object sender, EventArgs e)


{
{ this.Close(); }
}

private void button4_Click(object sender, EventArgs e)


{
listBox1.Items.Clear();
}
}
FAIQA MEHBOOB(032)
BSE IV-B
FJWU
}

TASK#2
Create form having personal Information of the user for job application.
After pressing submit button each information should be displayed in a listbox. If no option is selected
error should be generated indicating the warning accordingly.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
listBox4.Items.Add("Name " + textBox1.Text + "\n");

listBox4.Items.Add("Roll Num " + textBox2.Text + "\n");

listBox4.Items.Add("Session " + comboBox1.SelectedItem + "\n");

listBox4.Items.Add("Email " + textBox3.Text + "\n");

listBox4.Items.Add("Nationality " + comboBox2.SelectedItem + "\n");

listBox4.Items.Add("Religion " + comboBox3.SelectedItem + "\n");

listBox4.Items.Add("Political Affiliation " + comboBox4.SelectedItem + "\n");

listBox4.Items.Add("Previous Experience " + textBox4.Text + "\n");


FAIQA MEHBOOB(032)
BSE IV-B
FJWU

listBox4.Items.Add("Total no of Experience " + comboBox5.SelectedItem + "\n");

listBox4.Items.Add("Post Applied For " + listBox1.SelectedItem + "\n");

listBox4.Items.Add("Pay Scale " + listBox2.SelectedItem + "\n");

listBox4.Items.Add("Is Application Fee Submitted? " + listBox3.SelectedItem + "\n");

listBox4.Visible = true;
}}}

Task#3
Create a simple Guess the number Game in c#.Computer will assume any number from 0-9 and
player
should guess that number. If player guess the number correctly message should be displayed.
“Player 1
wins” Else “Computer Wins”
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
FAIQA MEHBOOB(032)
BSE IV-B
FJWU
{
InitializeComponent();
private void button1_Click(object sender, EventArgs e)
{
Random temp = new Random();
int a = temp.Next(0, 9);

{
if (textBox1.Text == a.ToString())
MessageBox.Show("player wins" + a.ToString());
else
MessageBox.Show("sorry: Computer Wins..." + a.ToString());
textBox1.Clear();
textBox1.Focus(); }}}}

Task#4
Modify Task#03 give 3 chances to the player to guess the answer if player is able to guess
the answer in 3 turns then message should be displayed player1 wins else computer wins.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int count = 0;
int x;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


FAIQA MEHBOOB(032)
BSE IV-B
FJWU
{
{

Random r = new Random();


x = r.Next(0, 9);
if (count < 3)
{
if (r.ToString() == textBox1.Text)
{

MessageBox.Show("Player 1 Wins");
this.Close();
}
else
{
count++;
MessageBox.Show("Computer Wins" + " Remaining Turns " + (3 - count));
}
}
else
{
MessageBox.Show("game over ");
this.Close();
}
MessageBox.Show(x.ToString());
}}}}

Task#5
FAIQA MEHBOOB(032)
BSE IV-B
FJWU
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lab_08_05
{
public partial class Form1 : Form
{
int x;
public Form1()
{
InitializeComponent();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if(radioButton1.Checked==true)
{ Random obj = new Random();
x = obj.Next(0, 9);
}
if(radioButton2.Checked==true)
{ Random obj1 = new Random();
x = obj1.Next(0, 20);
}
if(radioButton3.Checked==true)
{ Random obj2 = new Random();
x = obj2.Next(0, 99);

}
if(textBox1.Text==Convert.ToString(x))
{ MessageBox.Show(&quot;player 1 wins&quot;); }
else
{ MessageBox.Show(&quot;player 2 turn&quot;); }
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox2.Text == Convert.ToString(x))
{ MessageBox.Show(&quot;player 2 wins&quot;); }
else
{ MessageBox.Show(&quot;player 1 turn&quot;); }
MessageBox.Show(x.ToString());
}
private void button4_Click(object sender, EventArgs e)
{
FAIQA MEHBOOB(032)
BSE IV-B
FJWU
textBox1.Text = &quot;&quot;;
textBox2.Text = &quot;&quot;;
x = 0;
radioButton1.Checked = false;
radioButton2.Checked = false;
radioButton3.Checked = false;}
private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == Convert.ToString(x))
{ MessageBox.Show(&quot;player 1 wins&quot;); }
else
{ MessageBox.Show(&quot;player 2 turn&quot;); }
MessageBox.Show(x.ToString());}}}

You might also like