0% found this document useful (0 votes)
6 views

Practical -4

Uploaded by

happylifehome924
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Practical -4

Uploaded by

happylifehome924
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

RadioButton Control

A radio button or option button enables the user to select a single option from a
group of choices when paired with other RadioButton controls. When a user clicks
on a radio button, it becomes checked, and all other radio buttons with same group
become unchecked

Add the following to above design

First step:

private void Form1_Load(object sender, EventArgs e)


{

this.redlbl.Visible = false;
bluelbl.Visible = false;
greenlbl.Visible = false;
}
Second step:

private void redrbtn_CheckedChanged(object sender, EventArgs


e)
{

if (redrbtn.Checked == true)
{
redlbl.Visible = true;
bluelbl.Visible = false;
greenlbl.Visible = false;
}
}

Third step:
private void bluerbtn_CheckedChanged(object sender, EventArgs
e)
{
if(bluerbtn.Checked == true )
{

bluelbl.Visible = true;
redlbl.Visible = false;
greenlbl.Visible = false;
}
}

Fourth step:

private void greenrbtn_CheckedChanged(object sender, EventArgs


e)
{
if (greenrbtn.Checked ==true )
{
greenlbl.Visible = true;
redlbl.Visible = false;
bluelbl.Visible = false ;
}
}
----------------------------------------------------------------------------------------------------

ListBox Control

The ListBox control is the simplest of the list-based controls and serves primarily to
display a
simple list of items in an easy-to-navigate user interface from which users can
select one or
more items.

First step:
The following code stepwise illustrate above design

Second step: write the following code under form load event

private void Form1_Load(object sender, EventArgs e)


{
this.listBox1.Items.Add("Sunday");
this.listBox1.Items.Add("Monday");
this.listBox1.Items.Add("Tuesday");
this.listBox1.Items.Add("Wednesday");
this.listBox1.Items.Add("Thursday");
this.listBox1.Items.Add("Friday");

Step no-3:

private void addbtn_Click(object sender, EventArgs e)


{

// preventing List Box from duplicate data

string str = this.textBox1.Text;


bool duplicate = false;
foreach (object obj in listBox1.Items)
{
if (obj.ToString() == str)
{
duplicate = true;
break;
}
}
if (duplicate)
{
MessageBox.Show("name already exist");
}
else if (this.textBox1.Text != "")
{
this.listBox1.Items.Add(this.textBox1.Text);
this.textBox1.Clear();
this.textBox1.Focus();

}
Step no-4:

private void removebtn_Click(object sender, EventArgs e)


{
this.listBox1.Items.Remove(listBox1.SelectedItem);

Step no-5:

private void showbtn_Click(object sender, EventArgs e)


{
// This code is used to select multi index
listBox1.SelectionMode = SelectionMode.MultiSimple ;
//this code is used to display SelectedItems through
message box
foreach (object obj in listBox1.SelectedItems)
{
MessageBox.Show(obj.ToString());
}
}
Step no-6:

private void loadlistbtn_Click(object sender, EventArgs e)


{
List<string> strlist = new List<string>();
strlist.Add("ali");
strlist.Add("raza");
strlist.Add("ajmal");

listBox1.DataSource = strlist;

//List<string> intlist = new List<string>();


//intlist.Insert(0, "Irfan");
//intlist.Insert(1, "Rashid");
//intlist.Insert(2, "Usman");
//listBox1.DataSource = intlist;

}
-------------------------------------------------------------------------------------------------------------------------------

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy