menu tools trip

12
Windows Form programming with VB.Net 2005. 1 Bu Bui 4: i 4: Menu Menu – ToolBar ToolBar ToolStrip ToolStrip ToolStripContainer ToolStripContainer StatusStrip StatusStrip MenuStrip MenuStrip MenuStripContext MenuStripContext NotifyIcon NotifyIcon Windows Form programming with VB.Net 2005. 2 ToolStrip ToolStrip TVisual Studio 2005 g Visual Studio 2005 gi ToolBar l i ToolBar là ToolStrip ToolStrip

Upload: huaduytam

Post on 21-Apr-2015

146 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Menu Tools Trip

Windows Form programming with VB.Net 2005. 1

BuBuổổi 4: i 4: Menu Menu –– ToolBarToolBar

ToolStrip ToolStrip ToolStripContainerToolStripContainerStatusStripStatusStripMenuStripMenuStripMenuStripContext MenuStripContext NotifyIconNotifyIcon

Windows Form programming with VB.Net 2005. 2

ToolStripToolStrip

TTừừ Visual Studio 2005 gVisual Studio 2005 gọọi ToolBar li ToolBar làà ToolStripToolStrip

Page 2: Menu Tools Trip

Windows Form programming with VB.Net 2005. 3

ToolStripToolStrip

1. 1. PropertiesProperties::-- Item: Item: QuQuảản lý vin lý việệc thêm (Add), xc thêm (Add), xóóa (remove) a (remove)

ccáác thc thàành phnh phầần cn củủa ToolStripa ToolStrip-- TextDirection: TextDirection: HiHiểển thn thịị Text cText củủa ca cáác thc thàành nh

phphầần cn củủa ToolStrip theo chia ToolStrip theo chiềều ngang u ngang ((HorizontalHorizontal), d), dọọc theo chic theo chiềều kim đu kim đồồng hng hồồ((Vertical90, Vertical270)Vertical90, Vertical270)……

-- LayoutStyle: LayoutStyle: XXáác đc địịnh vnh vịị trtríí ToolStrip theo ToolStrip theo chichiềều ngang (u ngang (HorizontalHorizontal), d), dọọc (c (VerticalVertical))……

-- RenderMode: RenderMode: XXáác đc địịnh lonh loạại ToolStrip theo chi ToolStrip theo chếế đđộộ System, System, ProfessionalProfessional……

Windows Form programming with VB.Net 2005. 4

Item cItem củủa ToolStrip: a ToolStrip: (ti(tiếếp theo)p theo)

Item Item ởở đây l đây làà mmộột đt đốối tưi tượợng thung thuộộc c ToolStripItem classToolStripItem class ququảản lý vin lý việệc thic thiếết kt kếế vvàà viviếết t code cho ToolStrip. Ccode cho ToolStrip. Cáác c ToolStripItemToolStripItem ởở đây đây thưthườờng lng làà: :

-- ToolStripButton (Button)ToolStripButton (Button)-- ToolStripLabel (Label)ToolStripLabel (Label)-- ToolStripSeparator ToolStripSeparator -- ToolStripTextBox (TextBox)ToolStripTextBox (TextBox)-- ToolStripComboBox (Combobox)ToolStripComboBox (Combobox)-- ToolStripDropDownButton, ToolStripSplitButtonToolStripDropDownButton, ToolStripSplitButton-- ToolStripProgressBar (Progressbar)ToolStripProgressBar (Progressbar)

Page 3: Menu Tools Trip

Windows Form programming with VB.Net 2005. 5

Item as ToolStripItem Item as ToolStripItem 1. Properties:1. Properties:-- Text: Text: NNộội dung ci dung củủa Itema Item-- TextAlign: TextAlign: Căn lCăn lềề cho Text so vcho Text so vớới ToolstripItemi ToolstripItem-- TextDirection: TextDirection: Text theo chiText theo chiềều ngang or du ngang or dọọcc-- TextImageRelation: TextImageRelation: Quan hQuan hệệ gigiữữa Text va Text vàà Image Image

(ch(chồồng ghng ghéép, p, trên, trên, dưdướới, i, trưtrướớc, sau) c, sau) •• OverlayOverlay•• ImageAboveTextImageAboveText•• TextAboveImageTextAboveImage•• ImageBeforeTextImageBeforeText•• TextBeforeImageTextBeforeImage

Windows Form programming with VB.Net 2005. 6

OverlayOverlay

ImageAboveTextImageAboveText

TextAboveImageTextAboveImage

ImageBeforeTextImageBeforeText

TextBeforeImageTextBeforeImage

Page 4: Menu Tools Trip

Windows Form programming with VB.Net 2005. 7

Item as ToolStripItem (tt)Item as ToolStripItem (tt)1. Properties:1. Properties:

-- Image: Image: image hiimage hiểển thn thịị

-- ImageAlign: ImageAlign: Căn lCăn lềề cho image so vcho image so vớới Toolstripi Toolstrip

-- ImageTransparent: ImageTransparent: llààm trong sum trong suốốt mt mààu of imageu of image

-- DisplayStyle: DisplayStyle: None, Text, Image, ImageAndTextNone, Text, Image, ImageAndText

-- Alignment: Alignment: ĐĐịịnh vnh vịị trtráái hay phi hay phảải ci củủa 1 Item bên a 1 Item bên trtráái hay phi hay phảải trên Toolstripi trên Toolstrip

Windows Form programming with VB.Net 2005. 8

ToolStripContainerToolStripContainer

Page 5: Menu Tools Trip

Windows Form programming with VB.Net 2005. 9

ToolStripContainerToolStripContainer

1. Properties:1. Properties:

-- Dock: Dock: đđịịnh dnh dạạng hing hiểển thn thịị cho Toolstripcontainercho Toolstripcontainer

-- LeftToolStripPanelVisible: LeftToolStripPanelVisible: True or FalseTrue or False

-- RightToolStripPanelVisible: RightToolStripPanelVisible: True or FalseTrue or False

-- TopToolStripPanelVisible: TopToolStripPanelVisible: True or FalseTrue or False

-- BottomToolStripPanelVisible: BottomToolStripPanelVisible: True or FalseTrue or False

Windows Form programming with VB.Net 2005. 10

StatusStripStatusStrip

1. 1. PropertiesProperties::-- Item: Item: QuQuảản lý vin lý việệc thêm (Add), xc thêm (Add), xóóa (remove) a (remove)

ccáác thc thàành phnh phầần cn củủa StatusStripa StatusStrip-- TextDirection: TextDirection: HiHiểển thn thịị Text cText củủa ca cáác thc thàành nh

phphầần cn củủa StatusStrip theo chia StatusStrip theo chiềều ngang u ngang ((HorizontalHorizontal), d), dọọc theo chic theo chiềều kim đu kim đồồng hng hồồ((Vertical90, Vertical270)Vertical90, Vertical270)……

-- LayoutStyle: LayoutStyle: XXáác đc địịnh vnh vịị trtríí StatusStrip theo StatusStrip theo chuchuềều ngang (u ngang (HorizontalHorizontal), d), dọọc (c (VerticalVertical))……

-- RenderMode: RenderMode: XXáác đc địịnh lonh loạại StatusStrip theo i StatusStrip theo chchếế đ độộ System, System, ProfessionalProfessional……

Page 6: Menu Tools Trip

Windows Form programming with VB.Net 2005. 11

Item cItem củủa StatusStrip: a StatusStrip: (ti(tiếếp theo)p theo)

Item Item ởở đây l đây làà mmộột đt đốối tưi tượợng thung thuộộc c ToolStripItem classToolStripItem class ququảản lý vin lý việệc thic thiếết kt kếế vvàà viviếết t code cho StatusStrip. Ccode cho StatusStrip. Cáác c ToolStripItem ToolStripItem ởở đây đây thưthườờng lng làà: :

-- ToolStripStatusLabel (Label):ToolStripStatusLabel (Label):-- ToolStripDropDownButton, ToolStripSplitButtonToolStripDropDownButton, ToolStripSplitButton-- ToolStripProgressBar (Progressbar)ToolStripProgressBar (Progressbar)

StatusStrip: Chủ yếu và thường dùng làToolStripStatusLabelToolStripStatusLabel

Windows Form programming with VB.Net 2005. 12

MenuStripMenuStrip

1. 1. PropertiesProperties::-- Item: Item: QuQuảản lý vin lý việệc thêm (Add), xc thêm (Add), xóóa (remove) a (remove)

ccáác thc thàành phnh phầần cn củủa MenuStripa MenuStrip-- TextDirection: TextDirection: HiHiểển thn thịị Text cText củủa ca cáác thc thàành nh

phphầần cn củủa MenuStrip theo chia MenuStrip theo chiềều ngang u ngang ((HorizontalHorizontal), d), dọọc theo chic theo chiềều kim đu kim đồồng hng hồồ((Vertical90, Vertical270)Vertical90, Vertical270)……

-- LayoutStyle: LayoutStyle: XXáác đc địịnh vnh vịị trtríí MenuStrip theo MenuStrip theo chuchuềều ngang (u ngang (HorizontalHorizontal), d), dọọc (c (VerticalVertical))……

-- RenderMode: RenderMode: XXáác đc địịnh lonh loạại MenuStrip theo i MenuStrip theo chchếế đ độộ System, System, ProfessionalProfessional……

Page 7: Menu Tools Trip

Windows Form programming with VB.Net 2005. 13

Item as ToolStripItem Item as ToolStripItem 1. Properties:1. Properties:-- Text: Text: NNộội dung ci dung củủa Itema Item-- TextAlign: TextAlign: Căn lCăn lềề cho Text so vcho Text so vớới Toolstripi Toolstrip-- TextDirection: TextDirection: Text theo chiText theo chiềều ngang or du ngang or dọọcc-- TextImageRelation: TextImageRelation: Quan hQuan hệệ gigiữữa Text va Text vàà Image Image

(trên, (trên, dưdướới, i, trưtrướớc, sau, chc, sau, chồồng ghng ghéép)p)-- Image: Image: image hiimage hiểển thn thịị-- ImageAlign: ImageAlign: Căn lCăn lềề cho image so vcho image so vớới Toolstripi Toolstrip-- ImageTransparent: ImageTransparent: llààm trong sum trong suốốt mt mààu of imageu of image-- DisplayStyle: DisplayStyle: None, Text, Image, ImageAndTextNone, Text, Image, ImageAndText-- Alignment: Alignment: ĐĐịịnh vnh vịị trtráái hay phi hay phảải ci củủa 1 Item bên a 1 Item bên

trtráái hay phi hay phảải trên Toolstripi trên Toolstrip

Windows Form programming with VB.Net 2005. 14

MenuItem as ToolStripMenuItem MenuItem as ToolStripMenuItem 1. Properties:1. Properties:-- Text: Text: NNộội dung ci dung củủa Itema Item-- TextAlign: TextAlign: Căn lCăn lềề cho Text so vcho Text so vớới ToolstripMenuItemi ToolstripMenuItem-- TextDirection: TextDirection: Text theo chiText theo chiềều ngang or du ngang or dọọcc-- TextImageRelation: TextImageRelation: Quan hQuan hệệ gigiữữa Text va Text vàà Image Image (trên, (trên,

dưdướới, i, trưtrướớc, sau, chc, sau, chồồng ghng ghéép)p)-- Image: Image: image hiimage hiểển thn thịị-- ImageAlign: ImageAlign: Căn lCăn lềề cho image so vcho image so vớới ToolstripMenuItemi ToolstripMenuItem-- ImageTransparent: ImageTransparent: llààm trong sum trong suốốt mt mààu of imageu of image-- DisplayStyle: DisplayStyle: None, Text, Image, ImageAndTextNone, Text, Image, ImageAndText-- Alignment: Alignment: ĐĐịịnh vnh vịị trtráái hay phi hay phảải ci củủa 1 Item bên tra 1 Item bên tráái hay i hay

phphảải trên ToolstripMenuItemi trên ToolstripMenuItem

Page 8: Menu Tools Trip

Windows Form programming with VB.Net 2005. 15

Item cItem củủa MenuStrip: a MenuStrip: (ti(tiếếp theo)p theo)

Item Item ởở đây l đây làà mmộột MenuItem lt MenuItem làà đ đốối tưi tượợng thung thuộộc c ToolStripMenuItem classToolStripMenuItem class ququảản lý vin lý việệc thic thiếết kt kếế vvààviviếết code cho MenuStrip. t code cho MenuStrip. ToolStripMenuItem ToolStripMenuItem ởở đây thưđây thườờng lng làà: :

-- ToolStripComboBoxToolStripComboBox-- ToolStripTextBoxToolStripTextBox-- ToolStripSeparator ToolStripSeparator -- DropDownItems: DropDownItems: thuthuộộc tc tíính knh kếế ththừừa cha con a cha con

nghnghĩĩa la làà trong mtrong mộột MenuItem ct MenuItem cóó DropDownItems DropDownItems vvàà trong mtrong mộột DropDownItems ct DropDownItems cóó ththểể ccóóMenuItem khMenuItem kháácc…… theo ththeo thứứ ttựự phân cphân cấấp thư mp thư mộột t cây thư mcây thư mụụcc

Windows Form programming with VB.Net 2005. 16

ToolStripItem Container Support ToolStripItem Container Support

Class ToolStrip

MenuStrip

StatusStrip

ToolStripButton Yes No NoToolStripComboBox Yes Yes NoToolStripSplitButton Yes No NoToolStripLabel Yes No NoToolStripSeparator Yes Yes NoToolStripDropDownButton Yes No NoToolStripTextBox Yes Yes YesToolStripMenuItem No Yes NoToolStripStatusLabel No No YesToolStripProgressBar Yes No Yes

Page 9: Menu Tools Trip

Windows Form programming with VB.Net 2005. 17

ToolStripMenuItem MembersToolStripMenuItem Members

1. Properties-- Checked:Checked: KiKiểểm tra trm tra trạạng thng tháái Checked hay không i Checked hay không Checked cChecked củủa ToolStripMenuItem (True or False)a ToolStripMenuItem (True or False)-- ShortcutKeys:ShortcutKeys: ChChỉỉ ra shortcut key (phra shortcut key (phíím tm tắắt) khi gt) khi gọọi i ToolStripMenuItem VD: Ctrl+N ToolStripMenuItem VD: Ctrl+N ……-- ShowShortcutKeys: ShowShortcutKeys: Cho phCho phéép p ẩẩn or hin or hiệện Shortcut keyn Shortcut key-- ShortcutKeyDisplayString:ShortcutKeyDisplayString: nnếếu u ShowShortcutKeysShowShortcutKeysbbằằng ng TrueTrue ta cta cóó ththểể cho hicho hiểển thn thịị phphíím tm tắắt đt đảảo vo vịị trtríí ccủủa a phphíím chm chứức năngc năng. Vd: Shift+Ctrl+N thay v. Vd: Shift+Ctrl+N thay vìì hihiểển thn thịịCtrl+Shift+NCtrl+Shift+N

2. Event:-- CheckedChanged:CheckedChanged: Handle this event to respond when Handle this event to respond when the item is the item is checkedchecked or or uncheckedunchecked..

Windows Form programming with VB.Net 2005. 18

ContextMenuStripContextMenuStrip

-- Window Form cWindow Form cóó hai lohai loạại Menu li Menu làà Main menu Main menu vvàà Context menu Context menu. C. Context menu như lontext menu như làà ““Pop Pop up menuup menu”” thư thườờng cung cng cung cấấp cho User thp cho User thựực hic hiệện n viviệệc rightc right--click đclick đểể ththựực hic hiệện mn mộột pht phầần tn táác vc vụụtrên Windows form. trên Windows form.

-- HHầầu hu hếết tt tấất ct cảả ccáác Control thưc Control thườờng cng cóó thuthuộộc tc tíích ch ContextMenuStrip khi đContextMenuStrip khi đốối tưi tượợng đng đóó đư đượợc gc gáán n (Set) b(Set) bằằng mng mộột ContextMenuStrip đưt ContextMenuStrip đượợc tc tạạo vo vààxxửử lý slý sựự kikiệện (Event) thn (Event) thựực hic hiệện vin việệc rightc right--click click ththìì ContextMenuStrip sContextMenuStrip sẽẽ đư đượợc Display or Showc Display or Show

Page 10: Menu Tools Trip

Windows Form programming with VB.Net 2005. 19

NotifyIconNotifyIcon-- DiDiễễn tn tảả Icon cIcon củủa Window Form va Window Form vềề trtrạạng thng tháái i

System Tray (StaskBar) System Tray (StaskBar) -- NottifyIcon liên quan đNottifyIcon liên quan đếến trn trạạng thng tháái ci củủa Window a Window

Form: theForm: theo đo đốối tưi tượợng ng WindowStateWindowState bao gbao gồồm: m: •• FormWindowState.MaximizedFormWindowState.Maximized•• FormWindowState. NormalFormWindowState. Normal•• FormWindowState. MinimizedFormWindowState. Minimized

1. Properties:1. Properties:-- Icon:Icon: Icon hiIcon hiểển thn thịị ởở TaskBarTaskBar-- ContextMenuStripContextMenuStrip:: Set ContextMenuStrip cho Set ContextMenuStrip cho

NotifyIconNotifyIcon

Windows Form programming with VB.Net 2005. 20

MaskedTextBox & RichTextBoxMaskedTextBox & RichTextBox

-- MaskedTextBox & RichTextBoxMaskedTextBox & RichTextBox: c: cóó ttấất ct cảả ccáác c Properties vProperties vàà Event như m Event như mộột TextBox vt TextBox vàà ccóó đ đặặc c điđiểểm riên sau:m riên sau:

-- RichTextBox:RichTextBox: tương đương m tương đương mộột TextBox t TextBox ởở ddạạng ng MultiLine=True MultiLine=True

-- MaskedTextBox:MaskedTextBox: ccóó Properties (thuProperties (thuộộc tc tíính) nh) MaskMaskcho phcho phéép đp địịnh dnh dạạng cng cáách thch thứức hic hiểển thn thịị vvàà nhnhậập p thông tin vthông tin vàào theo mo theo mộột đt địịnh dnh dạạng đã đưng đã đượợc đc địịnh snh sẵẵn n vvíí ddụụ như ng như ngàày thy thááng, Ging, Giờờ, s, sốố, chu, chuỗỗii…… __/__/___ ; __/__/___ ; 061061--38765433876543

Page 11: Menu Tools Trip

Windows Form programming with VB.Net 2005. 21

Windows Form programming with VB.Net 2005. 22

Page 12: Menu Tools Trip

Windows Form programming with VB.Net 2005. 23

MaskedTextBox FormatMaskedTextBox Formatelement Description

0 Chỉ đư được nhập vào số, nếu không nhập vào sẽ nhận khoảng trắng 9 nhập số hoặc khoảng trắng # Digit or space, optional. If this position is blank in the mask, it will be

rendered as a space in the text property. Plus (+) and minus (-) signs are allowed.

L Letter, required. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z] in regular expressions.

? Letter, optional. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z]? in regular expressions.

& Character, required. If the AsciiOnly property is set to true, this element behaves like the "L" element.

C Character, optional. Any non-control character. If the AsciiOnlyproperty is set to true, this element behaves like the "?" element.

A Alphanumeric, optional. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z.

a Alphanumeric, optional. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z.

Windows Form programming with VB.Net 2005. 24

MaskedTextBox FormatMaskedTextBox Formatelement Description

. Decimal placeholder. The actual display character used will be the decimal placeholder appropriate to the format provider, as determined by the control's FormatProvider property.

, Thousands placeholder. The actual display character used will be the thousands placeholder appropriate to the format provider, as determined by the control's FormatProvider property.

: Time separator. The actual display character used will be the time placeholder appropriate to the format provider, as determined by the control's FormatProvider property.

/ Date separator. The actual display character used will be the date placeholder appropriate to the format provider, as determined by the control's FormatProvider property.

$ Currency symbol. The actual character displayed will be the currency symbol appropriate to the format provider, as determined by the control's FormatProvider property.

< Shift down. Converts all characters that follow to lowercase.

> Shift up. Converts all characters that follow to uppercase.

| Disable a previous shift up or shift down.

\ Escape. Escapes a mask character, turning it into a literal. "\\" is the escape sequence for a backslash.