Windowsforms 2 (Listbox)
Windowsforms 2 (Listbox)
===========
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_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();
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;
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;
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
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);
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
images
digital album
========
public partial class:form
i=0;
TIMER1_CLICK
=========
picturebox1.image=imagelist1.images[i];
i++;
if(i==imagelist1.images.count)
{
i=0;
}
list box:-
=====
advantage:- we can display group of items to the user.
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
main menu
=======
this will be available at the top of the application
context/shortcut menu
================
this menu is displayed when users clicks right mouse button with the application
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
select textbox properties goto context menu property select context menu strip
control