1. Trang chủ
  2. » Công Nghệ Thông Tin

Bài giảng Lập trình C# 2010: Chương 2.2 - ĐH Công nghệ Đồng Nai

57 30 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề DateTimePicker & MonthCalendar
Trường học Dong Nai University of Technology
Thể loại bài giảng
Thành phố Đồng Nai
Định dạng
Số trang 57
Dung lượng 4,63 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Bài giảng Lập trình C# 2010: Chương 2.2 trình bày các nội dung tiếp theo của chương 2 về DateTimePicker & MonthCalendar, các thao tác cơ bản, nút lệnh và tính năng của nó, cách thức thực hiện cùng một số nội dung khác.

Trang 3

Name Description

Format 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

Trang 4

d The one- or two-digit day

dd The two-digit day Single-digit day values are preceded by a 0

ddd The three-character day-of-week abbreviation

dddd The full day-of-week name

h The one- or two-digit hour in 12-hour format

hh The two-digit hour in 12-hour format Single digit values are preceded

by a 0

H The one- or two-digit hour in 24-hour format

Trang 5

HH The two-digit hour in 24-hour format Single digit values are preceded by a 0

m The one- or two-digit minute

mm The two-digit minute Single digit values are preceded by a 0

M The one- or two-digit month number

mm The two-digit minute Single digit values are preceded by a 0

M The one- or two-digit month number

MM The two-digit month number Single digit values are preceded by a 0

MMM The three-character month abbreviation

Trang 6

MMMM The full month name

s The one- or two-digit seconds

ss The two-digit seconds Single digit values are preceded by a 0

t 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 The last two digits of the year (2001 is displayed as "01")

yyyy The full year (2001 is displayed as "2001")

Trang 7

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);

}

ListBox

Trang 8

A nd W e can use A ddR ange m ethod to add data:

private void frm ListBox_Load(object sender, EventArgs e)

{

string[] strArr = new string[] { "Tèo","Tí","Bin","Bo"};

listBox1.Item s.AddRange(strArr);

}

Trang 9

{ private string m _strID ;

private string m _strN am e;

public C S tudent( string strID ,

string strN am e) { this m _strID = strID ;

this m _strN am e = strN am e;

}

public string ID

{ get { return this m _strID ; }

set { this m _strID = value ; }

}

public string N am e

{ get { return this m _strN am e; }

set { this m _strN am e = value ; }

}

}

Trang 10

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" ;

A lso W e can use D ataSource to display data

Trang 11

To get object from Listbox, W e could use coding below :

if (listBox1.SelectedItem != null )

{

CStudent svTeo = ( CStudent )

listBox1.SelectedItem ; lblM essage.Text = aStudent.N am e

+ " W as selected" ; }

Trang 13

U se Item s to add data

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 ddR ange

chklbLeft.Items.AddRange(new string[] { "Tèo","Tí","Bin","Bo"});

Trang 14

H ow to process Item s C hecked ???

Trang 15

H ow to process Item s C hecked ???

Trang 16

H ow to process Item s C hecked ???

C ase 3:

for (int i = 0; i < chklbLeft.Item s.Count; i+ + ){

if (chklbLeft.G etItem C hecked(i))

{

//Process Item checked here

}

}

Trang 17

G o back C hecklistB ox Exam ple:

private void btnAdd_Click

(object sender, EventArgs e)

foreach ( string s in chklbRight.Item s)

{chklbLeft.Item s.Rem ove(s);}

}

Trang 18

private void btnAddAll_Click

( object sender, EventArgs e)

{ chklbRight.Item s.AddRange

(chklbLeft.Item s); chklbLeft.Item s.Clear();

}

Trang 19

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);

}

Trang 20

private void btnRem oveAll_Click

( object sender, EventArgs e)

Trang 21

Menu (2 ways to use)

Property

Trang 22

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 !

Trang 23

Coding to create Menu at Runtime

Trang 24

private M enuItem m enuFile, m enuEdit, m enuFileN ew , m enuFileO pen,

m enuFileExit, m enuEditCut, m enuEditCopy, m enuEditPaste;

private void createM enu()

{

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);

Trang 25

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();}

Trang 26

private void attachEvents()

Trang 27

(object sender, EventArgs e)

private void frm M enuB asic_Load

(object sender, EventArgs e)

{createM enu();

}

Trang 28

MenuStrip

Trang 29

Click on button to add MenuItem

Trang 30

Text to Display

Click here to add Sub MenuItem

MenuItem’s Name

Trang 31

Image Icon

Text to Display

Click here to add Sub MenuItem

MenuItem’s Name

Trang 32

We could add MenuItem direct on the Windows Form

Enter Name in the “Type Here”

Trang 33

Add Event for each

MenuItem

Trang 34

Image List

Drag & Drop

Trang 35

Gets the ImageList

ImageCollection for this image list See Next Slide

Gets or sets the size of the

images in the image list

image list

Trang 36

Click Add button to insert

Image into Collection

Trang 37

Select image & click Open

Trang 38

At

Runtime

Trang 39

private M enuStrip m enuBar;

private ToolStripM enuItem m enuFile, m enuEdit,

m enuFileN ew , m enuFileO pen, m enuFileExit,

m enuEditCut, m enuEditCopy, m enuEditPaste;

Trang 40

{ m enuBar = new M enuStrip();

m enuBar.Font = new Font ( "arial" , 36, FontStyle.Bold,

G raphicsU nit Pixel);

this M ainM enuStrip = m enuBar;

m enuFile = new ToolStripM enuItem ( "File" );

m enuFileN ew = new ToolStripM enuItem ( "N ew " );

m enuFileN ew Im age = im ageList1.Im ages[0];

Trang 41

ToolStripSeparator sp = new ToolStripSeparator ();

m enuFileExit = new ToolStripM enuItem ( "Exit" );

m enuFileExit.Im age = im ageList1.Im ages[1];

m enuFile.D ropD ow nItem s.Add(

m enuFileN ew );

m enuFile.D ropD ow nItem s.Add(

m enuFileO pen);

Trang 42

m enuFile.D ropD ow nItem s.Add(sp);

m enuFile.D ropD ow nItem s.Add(

m enuFileExit);

m enuEdit = new ToolStripM enuItem ( "Edit" );

m enuEditCut = new ToolStripM enuItem ( "Cut" );

m enuEditCopy = new ToolStripM enuItem ( "Copy" );

m enuEditPaste = new ToolStripM enuItem ( "Paste" );

Trang 44

private void frm M enuStrip_Load

( object sender, EventArgs e)

{

createM enu();

}

Trang 45

Drag & Drop into the

FORM

Trang 46

Click Items (Collection) to add MenuItem

ImageScalingSize to set Width, Height Icon

Trang 47

As the same

MenuStrip

Trang 48

1.Choose button

2.Set ContextMenuStrip

3.Attach event as the same MenuStrip

Trang 49

ToolStripContainer & ToolStrip

Trang 50

ToolStripContainer

Trang 51

ToolStripContainer Provides panels on each side of the form and a central panel that can

hold one or more controls

Trang 52

Drag & Drop

ToolStrip into

the Form

Trang 53

As the same

MenuStrip

Trang 54

Add Items Collection for ToolBar

Trang 55

Attach Events for each

Item

Trang 56

(for Student)

Coding ContextMenuStrip & ToolStrip at

Runtime

Trang 57

END

Ngày đăng: 08/05/2021, 12:20

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm