0% found this document useful (0 votes)
39 views8 pages

Windowsforms 2 (Listbox)

This document describes various controls in Windows Forms like list box, button, label, text box, check box, common dialog controls, tree view, timer, picture box, radio buttons, combo box, menu and context menu. It provides code examples for handling events of these controls and setting their properties.

Uploaded by

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

Windowsforms 2 (Listbox)

This document describes various controls in Windows Forms like list box, button, label, text box, check box, common dialog controls, tree view, timer, picture box, radio buttons, combo box, menu and context menu. It provides code examples for handling events of these controls and setting their properties.

Uploaded by

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

list box control

===========
this contol is used to display group of items to the user.so that user can select a
single item or group of items randomly

BUTTON1(ADD) BUTTON2(INSERT) BUTTON3(REMOVE) BUTTON4(REMOVEAT) BUTTON5(CLEAR)


BUTTON6(CLOSE)

LEBEL1(ENTER ANY ITEM) LABEL2(ENTER INDEX VALUE)

BUTTON1_CLICK
==========
listbox.items.add(textbox.text)

BUTTON2_CLICK
===========
listbox1.items.insert(convert.toint32(textbox2.text),textbox1.text);

BUTTON3_CLICK
===========
listbox1.items.remove(textbox1.text);

BUTTON4_CLICK
==========
listbox1.items.removeat(convert.toint32(textbox2.text);

BUTTON5_CLICK
===========
listbox1.items.clear();

BUTTON6_CLICK
============
this.close();

creating controls dynamically


====================
1.creating object for respective control class

2.setting the required properties to the object

3.adding this object to the controls collection of form class

BUTTON1_CLICK
==========
TextBox t1=new TextBox();
t1.left=200;
t1.top=50;
this.controls.Add(t1);
Label l1=new Label();
l1.left=10;
l1.top=50;
l1.AutoSize=true;
l1.text="Enter Any Text";
this.controls.Add(l1);

=======================
checkbok control
==========
this control is used to provide selection of more than one option from the given
group of options

BUTTON1_CLICK
==========
string s=textbox1.text+"hobbies are :";
if (checkbox1.checked==true)
s=s+checkbox1.text+" ";
if(checkbox2.checked==true)
s=s+checkbox2.text+" ";
if(checkbox3.checked==true)
s=s+checkbox3.text+" ";
if(checkbox4.checked==true)
s=s+checkbox4.text+" ";
label1.text=s;

common dialog controls


===============
these controls are used to perform some tasks like opening a file,saving a
file,applying font attributes,color attributes,performing page

settings, print settings etc.

types of common dialog controls


=====================
open file dialog control

open file dialog control


===============
this control is used to display,open file dialog box to the user so that user can
select any file to open

save file dialog control


==============
this control is used to display save file dialog box to the user so that user can
enter any file name to save

font dialog control


===========
this control is used to display font dialog box th the user , so that user can
select required font attributes to apply to the required data

color dialog control


============
this control is used to display color dialog box to the user so that user can
select required color to apply to the required data

BUTTON1_CLICK
===========
openfiledialog1.filter="TextFiles|*.txt|Word Document|*.doc|All Files|*.*";
openfiledialog1.showDialog();
text1.text=openfileDialog1.filename;

BUTTON2_CLICK(SAVE EXAMPLE)
=======================
savefileDialog1.showDialog1();
textbox1.text=savefileDialog1.Filename;
BUTTON3_CLICK(FONT EXAMPLE)
=====================
fontDialog1.showDialog1();
textbox1.font=fontDialog1.font;

BUTTON4_CLICK(COLOR EXAMPLE)
======================
colorDialog1.showDialog();
textbox1.foreColor=colorDialog1.color;

tree view control


===========
this control is used to display the required item or data in hieracial manner

BUTTON1_CLICK
===========
treeview.nodes.add("Sai Trust")
treeview.nodes.add("Govt Trust")
treeview.nodes.add("public Trust")
treeview.nodes[0].nodes.add("Schools")
treeview.nodes[0].nodes.add("Colleges")
treeview.nodes[0].nodes.add("Homes")
treeview.nodes[0].nodes[0].nodes.add("primary school")
treeview.nodes[0].nodes[0].nodes.add("high school")
treeview.nodes[0].nodes[1].nodes.add("junior College")
treeview.nodes[0].nodes[1].nodes.add("Degree College")
treeview.nodes[0].nodes[1].nodes.add("pg College")
treeview.nodes[0].nodes[1].nodes.add("Engg College")
treeview.nodes[0].nodes[2].nodes.add("OldAge Home")
treeview.nodes[0].nodes[2].nodes.add("Orphan Home")
treeview.nodes[0].nodes[2].nodes.add("primary Peace")

timer control
========
this control is used to execute the required code repeatedly again and again with
out any user involment

property
======
enable:- true

as long as enabled is true timer will be working.

default is false(i.e timer stops working

intervel:-time period in milli seconds. 1000 milli seconds=1 second

public partial class


int i=0;

TIMER1_TICK
========
if(i==0)
label.text="Orbit Technologies";
label.forecolor=color.blue
label.backcolor=color.yellow;
i=1;
}
else
{
label1.text="Hyderabad";
label1.backcolor=color.white
label1.forecolor=color.red
i=0;

============================
picture box control
==========
this control is used todisplay the images to the user on the form. we can display
images like JPEG,BMP,ICON,GIFF etc

BUTTON1_CLICK
===========
opendialog1.filter="jpeg files|*.jpg|Giff Files|*.Gif|Bitmap Files |*.Bmp|All
Files|*.*";
opendialog1.showDialog();
//pictureBox1.ImageLocation=openDialog1.filename;
picturebox1.image=image.fromfile(opendialog1.filename);

picture box properties


==============
image:-
=====
sets or gets the image to be displayed in the picture box control

image location
=========
sets or gets the file path of the image to be displayed in the picture box control

size mode
=======
normal(default)/stretch image/auto size/centre image

normal:-
=====
picture box and image will have there own sizes, there do not be any change in
image size when picture box changes

stretchImage
========
image will be scaled to picture box size, image size will increse or decrease
according to picture size

auto size
======
picture box will be scaled to image size. it is not possible to increse or
decrease either picture box size or image size

centre image
========
image will be displayed with in the centre location of picture box

grouping controls
============
the user can able to select one radio button but if the user would like to select
more then one radio button then we use grouping controls

1.group box
========
take 2 group controls and place 4 radio buttons for fore color and 4 radio buttons
for back ground colors

OPRED_CHECKEDCHANGED
=================
textbox1.backcolor=color.red

OPGREEN_CHECKEDCHANGED
===================
textbox1.backcolor=color.green

OPBLUE_CHECKEDCHANGED
==================
textbox1.backcolor=color.blue

OPWHILTE_CHECKEDCHANGED
====================
textbox1.backcolor=color.whilte

OPYELLOW_CHECKEDCHANGED
======================
textbox1.forcolor=color.yellow

OPMEGENTA_CHECKEDCHANGED
======================
textbox1.forecolor=color.megenta

OPGOLD_CHECKEDCHANGED
==================
textbox1.forecolor=color.gold

OPBLACK_CHECKEDCHANGED
====================
textbox1.forecolor=color.black

image list control


============
this control is used to store the images required to be used with in the
application. we can store the images like JPEG,BMP,GIFF,ICON

images

digital album
========
public partial class:form
i=0;

TIMER1_CLICK
=========
picturebox1.image=imagelist1.images[i];
i++;
if(i==imagelist1.images.count)
{
i=0;
}

combo box control


============
text box:-
====
advantage:-user can enter the data at run time

dis advantage:-it is not possible to display group of items to the user

list box:-
=====
advantage:- we can display group of items to the user.

dis-advantage:-we can not enter any data at run time

combox is combination of both text box and list box

namespace ComboBoxExample
{
public partial class Form1 : Form
{
//create reference variables
Label label1, label2, label3;
ComboBox combobox1;
public Form1()
{
InitializeComponent();
/* form properties */
this.Text = "ComboBox Example";
this.Font = new Font("Tahoma", 20);
this.Size = new Size(550, 300);
/* creating label1 */
label1 = new Label();
label1.Text = "Country: ";
label1.AutoSize = true;
label1.Location = new Point(50, 50);
this.Controls.Add(label1);
/* creating label2 */
label2 = new Label();
label2.Text = "Selected item here";
label2.AutoSize = true;
label2.Location = new Point(180, 120);
this.Controls.Add(label2);
/* creating label3 */
label3 = new Label();
label3.Text = "Selected index here";
label3.AutoSize = true;
label3.Location = new Point(180, 170);
this.Controls.Add(label3);
/* creating combobox1 */
combobox1 = new ComboBox();
combobox1.Size = new Size(200, 40);
combobox1.Location = new Point(180, 50);
combobox1.DropDownStyle = ComboBoxStyle.DropDownList;
string[] countries = new string[] { "India", "China", "UK", "USA", "Japan" };
combobox1.Items.AddRange(countries);
combobox1.SelectedIndexChanged += Combobox1_SelectedIndexChanged;
this.Controls.Add(combobox1);
}
private void Combobox1_SelectedIndexChanged(object sender, EventArgs e)
{
/* get selected item */
object obj = combobox1.SelectedItem;
string s = Convert.ToString(obj);
label2.Text = s;
/* get selected index */
int n = combobox1.SelectedIndex;
label3.Text = Convert.ToString(n);
}
}
}

==========================================
working with menus
============
any window based application will provide 2 types of menus

1. main menu 2. context menu

main menu
=======
this will be available at the top of the application

every application can contain only one main menu

to create main menu we have menu strip control

context/shortcut menu
================
this menu is displayed when users clicks right mouse button with the application

an application can contain any number of context menus based on requirment

to create main menu we have context menu strip control

SMENU_CLICK
=========
opendialog1.showDialog();
textbox1.text=opendialog1.filename

SMENUSAVE_CLICK
============
savedialog1.showDialog();
textbox1.text=savedialog1.filename;

SMENUEXIT_CLICK
===========
this.close();

SMENUfONT_CLICK
============
fontdialog1.showDialog();
textbox1.font=fontdialog1.font

SMENUFORECOLOR_CLICK
=================
colordialog1.showDialog();
textbox1.forecolor=colorDialog.color

SMENUBACKCOLOR_CLICK
=================
colordialog1.showDialog();
textbox1.backcolor=colorDialog1.color

contextmenu example
==============
MNUFONT_CLICK
===========
fontdialog1.showDialog();
textbox1.font=fontDialog1.font

SMENUFORECOLOR_CLICK
=================
colorDialog1.showDialog();
textbox1.forecolor=colorDialog1.color

SMNUBACKCOLOR_CLICK
================
colorDialog1.showDialog();
textbox1.backcolor=colorDialog1.color

note:-to assign contextmenu strip control to text box

select textbox properties goto context menu property select context menu strip
control

You might also like