Sunteți pe pagina 1din 6

CheckBox

By Default the checkbox event is checkBox1_CheckedChanged


CheckAlien property by default TopLeft
Checked property by default is False
TextAlien Property by default is MiddleLeft

RadioButton

For multiselection the panel is used. Because the form is a container control so it will
checked only one while using two or more radiobuttons.

Checked property by default is False


By Default the radiobutton event is radiobutton1_CheckedChanged

GroupBox

Used For More than one selection


A GroupBox control is a container control that is used to place Windows Forms child controls in a group. The purpose
of a GroupBox is to define user interfaces where we can categories related controls in a group.

RighttoLeft Property by default is No.

By Default event is groupBox1_Enter.

Numericupdown

A NumericUpDown control allows users to provide a spin (up/down) interface to move through predefined numbers using up and down arrows.

We can format the number of a NumericDropDown control using the


DecimalPlaces property.

By default Decimalplaces is 0.
Minimum =10,Maximum=20
By Default event is numericUpDown1_ValueChanged
Program
To change the value in numericupdown change in textbox

private void numericUpDown1_ValueChanged(object sender, EventArgs e)


{
textBox1.Text = Convert.ToString(numericUpDown1.Value);
}
Program
To change the numericupdown value through button
private void button3_Click(object sender, EventArgs e)
{
numericUpDown1.Value = numericUpDown1.Value + 1;
}

Increment Property is by default is 1.


RighttoLeft Property by default is No.

TrackBar

TrackBar control provides scrolling with a little different interface than a scrollbar.
Orientation propery :Horizontal property.
Minimum=0,Maximum=10
Small change=1 this is by the arrow keys <- ->
Large Change =5 this is by the page down and up button on keyboard.
Orientation property sets the horizontal or vertical orientation of a TrackBar control.
TickStyle property indicates how to display the tick marks on a TrackBar. It can be None,
TopLeft, BottomRight, or Both. By default BottomRight
By default event is trackBar1_Scroll.

Progress Bar

Minimum=0,Maximum=100
Value Property used to access the value which is 0 by default.
Style property is Blocks.
By Default event is progressBar1_Click
Value Property is the accessing property which is 0 by default.
Program
Change the value of Track bar change the values of progress bar

private void trackBar1_Scroll(object sender, EventArgs e)


{
progressBar1.Value = trackBar1.Value;
}
MonthCalendar

By default event is monthCalendar1_DateChanged

ShowWeekNumbers
Sets whether the month calendar control should display the week number to the left:
this.monthCalendar1.ShowWeekNumbers = true;

MaxSelectionCount property for Gets or sets the maximum number of days that can be
selected in a month calendar control.
To Dont show the day in calender
this.monthCalendar1.ShowToday = false;

To set the date on the label


private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
this.monthCalendar1.MaxSelectionCount = 1;
label1.Text = monthCalendar1.SelectionEnd.ToShortDateString();
}

DataTimePicker

Format property by default is Long=(Tuesday,march,2016)


Others
Long=(Tuesday,march,2016)
Short=3/2/2016
Time=11:03:03PM
Custom: 3/2/2016
MaxDate is by default 2/31/9998
Default event is dateTimePicker1_ValueChanged
ShowChackBox is by default is false
On false

On True

Showupdown is by default is false


On True

On False

Value Property is 4/21/2016 11:06 PM


MM=02
MMM=Mar,Feb,Jan etc
MMMM=March Febrary,January etc

MaskedTextBox

Default event is maskedTextBox1_MaskInputRejected


Masked Property is for different patterns like 000-000-000
Promtchar when format is visible by default is _

,,,,,,,,,,,,,,,,,,,,,,,

ListBox

Default event is listbox1.SelectedIndexChanged

Sorted Property is False By default.


Items Property is for items in listbox.
Datasource property is for source from others like database, from any list of string.
Program
How to load items in listbox on runtime on form load
{

private void Form1_Load(object sender, EventArgs e)


List<string> items = new List<string>();
items.Add("One");
items.Add("Two");
items.Add("Three");
listBox1.DataSource = items;
}
Program
How to enter new item in listbox by input value in textbox

Private void button2_Click(object sender, EventArgs e)


listBox2.Items.Add(textBox1.Text);
}
Program
How to swap items in one listbox to the other on button click

private void button1_Click(object sender, EventArgs e)


{
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
listBox2.Items.Add(listBox1.SelectedItems[i].ToString());
button1.Text =Convert.ToString(listBox1.SelectedItems.Count) + " item selected";
}
}
Program
How to count the listbox items
private void button4_Click(object sender, EventArgs e)
{
textBox2.Text = Convert.ToString(listBox2.SelectedItems.Count);
}
Program
How to remove the selected item in the list
private void button5_Click(object sender, EventArgs e)
{
int selectedindex = listBox2.SelectedIndex;
try
{
listBox2.Items.RemoveAt(selectedindex);
}
catch (Exception ex)
{
MessageBox.Show("plsease select any item");
}
}

SelectionMode One by default


Others
MultiSimple = select item by pressing ctrl button.
MultiExtended=select items by pressing shift and arrow key up and down
Combobox

1. A ComboBox control is a combination of a TextBox and a ListBox control. Only one list item is
displayed at one time in a ComboBox and other available items are loaded in a drop down list.

2. Default event is comboBox1_SelectedIndexChanged


3. Datasource and item properties for items
4. Program

Add items in Combobox


private void button1_Click(object sender, EventArgs e)
{
comboBox1.Items.Add(textBox1.Text);
}
5. Program
Remove the selected item in ComboBox
private void button2_Click(object sender, EventArgs e)
{

6. Program

comboBox1.Items.Remove(comboBox1.SelectedItem);
}

Search the item in combobox


>First Load the items in combobox on form load
7. private void Form1_Load(object sender, EventArgs e)
{
List<string> list = new List<string>();
list.Add("a");
list.Add("b");
list.Add("c");
list.Add("d");
comboBox1.DataSource = list;
}

>then search the item through textbox on button click

8. private void button4_Click(object sender, EventArgs e)


{
if (comboBox1.Items.Contains(textBox2.Text))
{
comboBox1.Text = textBox2.Text;
}
else
{
MessageBox.Show("there is no item ");
}
}
9. Program

How to swap the combobox item to another combobox


>First Load the items in combobox on form load
private void Form1_Load(object sender, EventArgs e)
{
List<string> list = new List<string>();
list.Add("a");
list.Add("b");
list.Add("c");
list.Add("d");
comboBox1.DataSource = list;
}
>then on the button paste that code
private void button5_Click(object sender, EventArgs e)
a. {
comboBox2.DataSource = list;
}
10. Program
To get all the items in messagebox
private void button6_Click(object sender, EventArgs e)

StringBuilder sb=new StringBuilder();


foreach (var item in comboBox1.Items)
{
sb.Append(item);
sb.Append(item);
}
MessageBox.Show(sb.ToString());
}

Listview
1. Default event is SelectedIndexChanged
2. A ListView control provides an interface to display a list of items using different views

including text, small images, and large images.

Domainupdown
1. A DomainUpDown control allows users to provide a spin (up/down) interface to move

through pre-defined strings using up and down arrows.


2. Default event is domainUpDown1_SelectedItemChanged
3. Scrollable is by default true for scrolling.
PictureBox
1. PictureBox control is used to display images in Windows Forms.
2. SizeMode property is Normal by default
StretchImage=the size u select for the image on design time.
Autosize=the original image size will appear on runtime.
CenterImage=the center of the image will show with original size of the image
3. ErrorImage property is used for the if image is not preset or not loading.
4. Load the image in picturebox through dialogbox
OpenFileDialog op = new OpenFileDialog();
if (op.ShowDialog() == DialogResult.OK)
{
1. pictureBox2.ImageLocation=op.FileName;
}
5. Image Property is used for set image.

Example
Bitmap bt = new Bitmap("C:\\Users\\Maxhar\\Pictures\\img.jpg");
pictureBox1.Image = bt;

6. ImageLocation property is used for load image from the disk or by the web

Example
pictureBox2.ImageLocation = "C:\\Users\\Maxhar\\Pictures\\img.jpg";