DONG NAI UNIVERSITY OF TECHNOLOGY
DONG NAI UNIVERSITY OF TECHNOLOGY
DateTimePicker & MonthCalendar
DONG NAI UNIVERSITY OF TECHNOLOGY
Name
Format
Description
Gets or sets the format of the date and time displayed in the
control
CustomFormat
Gets or sets the custom date/time format string
Value
Gets or sets the date/time value assigned to the control.
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
Next Slide to see list Custom Format
DONG NAI UNIVERSITY OF TECHNOLOGY
Format string
Description
d
dd
ddd
dddd
h
hh
H
The one- or two-digit day.
The two-digit day. Single-digit day values are preceded by a 0.
The three-character day-of-week abbreviation.
The full day-of-week name.
The one- or two-digit hour in 12-hour format.
The two-digit hour in 12-hour format. Single digit values are preceded
by a 0.
The one- or two-digit hour in 24-hour format.
DONG NAI UNIVERSITY OF TECHNOLOGY
Format string
Description
HH
m
mm
M
mm
M
MM
MMM
The two-digit hour in 24-hour format. Single digit values are preceded by a 0.
The one- or two-digit minute.
The two-digit minute. Single digit values are preceded by a 0.
The one- or two-digit month number.
The two-digit minute. Single digit values are preceded by a 0.
The one- or two-digit month number.
The two-digit month number. Single digit values are preceded by a 0.
The three-character month abbreviation.
DONG NAI UNIVERSITY OF TECHNOLOGY
Format string
Description
MMMM
s
ss
t
The full month name.
The one- or two-digit seconds.
The two-digit seconds. Single digit values are preceded by a 0.
The one-letter A.M./P.M. abbreviation (A.M. is displayed as "A").
tt
The two-letter A.M./P.M. abbreviation (A.M. is displayed as "AM").
y
The one-digit year (2001 is displayed as "1").
yy
yyyy
The last two digits of the year (2001 is displayed as "01").
The full year (2001 is displayed as "2001").
DONG NAI UNIVERSITY OF TECHNOLOGY
ListBox
private void
frm ListBox_Load(object sender, EventArgs e)
{
listBox1.Item s.Clear();
for (int i= 0; i< 10; i+ + )
listBox1.Item s.Add("Item " + i);
}
private void listBox1_SelectedIndexC hanged
(object sender,EventArgs e)
{
lblM essage.Text = listBox1.Text
+ " w as clicked!";
}
DONG NAI UNIVERSITY OF TECHNOLOGY
A n d W e can u se A d d R an g e m eth od to ad d d ata:
private void frm ListBox_Load(object sender, EventArgs e)
{
string[] strArr = new string[] { "Tèo","Tí","Bin","Bo"};
listBox1.Item s.AddRange(strArr);
}
p u b lic class C S tud ent
{
p rivate strin g m _strID ;
p rivate string m _strN am e;
p u b lic C S tud ent(string strID ,
string strN am e)
{ th is.m _strID = strID ;
this.m _strN am e = strN am e;
}
p u b lic string ID
{ g et { retu rn this.m _strID ; }
set { this.m _strID = value; }
}
p u b lic string N am e
{ g et { retu rn this.m _strN am e; }
set { this.m _strN am e = value; }
}
}
DONG NAI UNIVERSITY OF TECHNOLOGY
using System .Collections;
A lso W e can u se D ataS ou rce to d isp lay d ata
ArrayList arr = new ArrayList();
for(int i= 0;i< 10;i+ + )
{arr.Add(new
CStudent("ID _"+ i,"N am e "+ i));
}
listBox1.D ataSource = arr;
listBox1.ValueM em ber = "ID ";
listBox1.D isplayM em ber = "N am e";
DONG NAI UNIVERSITY OF TECHNOLOGY
DONG NAI UNIVERSITY OF TECHNOLOGY
To g et ob ject from Listb ox, W e cou ld u se cod in g b elow :
if (listBox1.SelectedItem != null)
{
CStudent svTeo = (CStudent )
listBox1.SelectedItem ;
lblM essage.Text = aStudent.N am e
+ " W as selected";
}
DONG NAI UNIVERSITY OF TECHNOLOGY
CheckedListBox
btnAdd
btnAddAll
chklbLef
chklbRight
btnRemove
btnRemoveAll
DONG NAI UNIVERSITY OF TECHNOLOGY
U se Item s to ad d d ata
private void frm CheckListBox_Load
(object sender, EventArgs e)
{ chklbLeft.Item s.Add("Tèo");
chklbLeft.Item s.Add("Tí");
chklbLeft.Item s.Add("Bin");
chklbLeft.Item s.Add("Bo");
}
O r w e could use A d d R an g e
chklbLeft.Items.AddRange(new string[] { "Tèo","Tí","Bin","Bo"});
DONG NAI UNIVERSITY OF TECHNOLOGY
H ow to p rocess Item s C h ecked ???
C ase 1 :
CheckedListBox.CheckedIndexCollection indexCollection =
chklbLeft.CheckedIndices;
string strChecked = "";
foreach (int i in indexCollection)
{
strChecked += i + ";";
}
MessageBox.Show(strChecked);
DONG NAI UNIVERSITY OF TECHNOLOGY
H ow to p rocess Item s C h ecked ???
C ase 2:
C h ecked ListB ox.C h ecked Item C ollection item s =
chklbLeft.CheckedItem s;
strin g strChecked = "";
foreach (string s in item s)
{
strChecked + = s + ";";
}
M essag eB ox.Show (strChecked);
DONG NAI UNIVERSITY OF TECHNOLOGY
H ow to p rocess Item s C h ecked ???
C ase 3 :
strin g strChecked = "";
for (int i= 0; i< chklbLeft.Item s.Count; i+ + ){
if (chklbLeft.G etItem C h ecked (i))
{
//Process Item checked here
}
}
DONG NAI UNIVERSITY OF TECHNOLOGY
G o b ack C h ecklistB ox Exam p le:
private void btnAdd_Click
(object sender,EventArgs e)
{
foreach(int iin chklbLeft.C heckedIndices)
{
chklbRight.Item s.Add(chklbLeft.Item s[i]);
}
foreach (string s in chklbRight.Item s)
{chklbLeft.Item s.Rem ove(s);}
}
DONG NAI UNIVERSITY OF TECHNOLOGY
private void btnAddAll_Click
(object sender, EventArgs e)
{
chklbRight.Item s.AddRange
(chklbLeft.Item s);
}
chklbLeft.Item s.Clear();
DONG NAI UNIVERSITY OF TECHNOLOGY
private void btnRem ove_Click
(object sender, EventArgs e)
{
foreach (string s in
chklbRight.CheckedItem s)
chklbLeft.Item s.Add(s);
foreach(string s in chklbLeft.Item s)
chklbRight.Item s.Rem ove(s);
}
DONG NAI UNIVERSITY OF TECHNOLOGY
private void btnRem oveAll_Click
(object sender, EventArgs e)
{
chklbLeft.Item s.AddRange
(chklbRight.Item s);
chklbRight.Item s.C lear();
}
DONG NAI UNIVERSITY OF TECHNOLOGY
Menu (2 ways to use)
MainMenu
MenuStrip
MenuItem
ToolStripMenuItem
Menu Property
MainMenuStrip
Property
DONG NAI UNIVERSITY OF TECHNOLOGY
I would like to tell you : using MainMenu is the basic
Menu.
In this case, I will demo add Menu at Runtime for you.
Please see next slide !
DONG NAI UNIVERSITY OF TECHNOLOGY
Coding to create Menu at Runtime
private M ain M en u m ainM enuBar;
DONG NAI UNIVERSITY OF TECHNOLOGY
private M en u Item m enuFile, m enuEdit, m enuFileN ew , m enuFileO pen,
m enuFileExit, m enuEditC ut, m enuEditC opy, m enuEditPaste;
p rivate void createM en u ()
{
m ainM enuBar = new M ainM enu();
this.M enu = m ainM enuBar;
m enuFile= new M enuItem ("File");
m enuFileN ew = new M enuItem ("N ew ");
m enuFileO pen = new M enuItem ("O pen");
m enuFileExit = new M enuItem ("Exit");
m enuFile.M enuItem s.Add(m enuFileN ew );
m enuFile.M enuItem s.Add(m enuFileO pen);
DONG NAI UNIVERSITY OF TECHNOLOGY
p rivate void createM en u (){ … …
m enuFile.M enuItem s.Add("-");
m enuFile.M enuItem s.Add(m enuFileExit);
m ainM enuBar.M enuItem s.Add(m enuFile);
m enuEdit = new M enuItem ("Edit");
m enuEditCut = new M enuItem ("Cut");
m enuEditCopy = new M enuItem ("Copy");
m enuEditPaste = new M enuItem ("Paste");
m enuEdit.M enuItem s.AddRange(new M enuItem []
{ m enuEditCut,m enuEditCopy,m enuEditPaste});
m ainM enuBar.M enuItem s.Add(m enuEdit);
attachEvents();}