Control Class – Quản lý mã lệnh Quản docx

21 293 0
Control Class – Quản lý mã lệnh Quản docx

Đ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

04/07/2010 1 Windows Form programming with VB.Net 2005. 1 Buổi Buổi 22: : Control Class Control Class –– QuảQuản n lý mã lý mã llệệnhnh  Data type Cấu trúc rẽ nhánh  Cấu trúc Lặp  Khai báo biến, mảng  Các phép toán thông dụng.  Tìm hiểu Control Class Windows Form programming with VB.Net 2005. 2 Data typeData type SizeSize RangeRange ShortShort 2 bytes2 bytes 32,768 32,768 ÆÆ 32,76732,767 UShortUShort 2 bytes2 bytes 0 0 ÆÆ 65,53565,535 IntegerInteger 4 bytes4 bytes 2,147,483,648 2,147,483,648 ÆÆ 2,147,483,6472,147,483,647 UIntegerUInteger 4 bytes4 bytes 0 0 ÆÆ 4,294,967,2954,294,967,295 LongLong 8 bytes8 bytes 9,223,372,036,854,775,808 to 9,223,372,036,854,775,8079,223,372,036,854,775,808 to 9,223,372,036,854,775,807 ULongULong 8 bytes8 bytes 0 0 ÆÆ 18,446,744,073,709,551,61518,446,744,073,709,551,615 SingleSingle 4 bytes4 bytes 3.4028235E+38 3.4028235E+38 ÆÆ 3.4028235E+383.4028235E+38 DoubleDouble 8 bytes8 bytes 1.79769313486231E+308 1.79769313486231E+308 ÆÆ 1.79769313486231E+3081.79769313486231E+308 DecimalDecimal 16 bytes16 bytes values up to +/values up to +/ 79,228 x 102479,228 x 1024 ByteByte 1 byte1 byte 0 0 ÆÆ 255 (no negative numbers)255 (no negative numbers) SByteSByte 1 byte1 byte 128 128 ÆÆ 127127 CharChar 16 bytes16 bytes Any Unicode symbol in the range 0Any Unicode symbol in the range 0––65,53565,535 StringString 2 bytes per 2 bytes per charactercharacter 0 to 2 billion Unicode characters0 to 2 billion Unicode characters BooleanBoolean 2 bytes2 bytes True or FalseTr ue or F al se DateDate 8 bytes8 bytes January 1, 0001, January 1, 0001, ÆÆ December 31, 9999December 31, 9999 ObjectObject 4 bytes4 bytes Can cpntain data of any typeCan cpntain data of any type 04/07/2010 2 Windows Form programming with VB.Net 2005. 3 BiBiếến:n: * Khai báo biến: Dim <name> as <DataType> Vd: Dim x as Integer * Khai báo mảng: Dim <name> (so) as <DataType> Vd: Dim Diem(4) as Integer ReDim diem(5) Windows Form programming with VB.Net 2005. 4 CáCác c phéphép p toátoán:n: PhéPhéo o toátoánnMô tảMô tả ++CộngCộng −− TrừTrừ **NhânNhân //ChiaChia \\ Chia lấy phần nguyênChia lấy phần nguyên ModMod Chia lấy phần dưChia lấy phần dư ^^Lũy thừaLũy thừa &&Nối 2 chuỗiNối 2 chuỗi 04/07/2010 3 Windows Form programming with VB.Net 2005. 5 CáCác c phéphép p toátoán n rúrút t gọgọn:n: OperationOperation ++ X = X + 6X = X + 6 X += 6X += 6 X = X X = X ––66X X = 6= 6 **X = X * 6X = X * 6 X *= 6X *= 6 //X = X / 6X = X / 6 X /= 6X /= 6 \\X = X X = X \\66X X \\= 6= 6 ^^X = X ^ 6X = X ^ 6 X ^= 6X ^= 6 (&)(&) X = X & "ABC"X = X & "ABC" X &= "ABC"X &= "ABC" Windows Form programming with VB.Net 2005. 6 ToáToán tn tử ử so so sásánh:nh: OperatorOperator Mô tảMô tả >>Lớn hơnLớn hơn <<Nhỏ hơnNhỏ hơn >=>= Lớn hơn hoặc bằngLớn hơn hoặc bằng <=<= Lớn hơn hoặc bằngLớn hơn hoặc bằng ==BằngBằng <><> KhácKhác 04/07/2010 4 Windows Form programming with VB.Net 2005. 7 PhéPhép p toátoán logicn logic OperatorOperator Mô tảMô tả NotNot Phủ địnhPhủ định AndAnd True And True = True True And True = True (TH còn lại là False)(TH còn lại là False) OrOr False Or False = FalseFalse Or False = False (TH Còn lại là True)(TH Còn lại là True) XorXor = True 2 vế SS phủ định nhau= True 2 vế SS phủ định nhau = False 2 vế SS Không phủ định nhau= False 2 vế SS Không phủ định nhau Windows Form programming with VB.Net 2005. 8 CCấấu u trútrúc c rẽ nhárẽ nhánh:nh: IfIf <ĐK><ĐK> ThenThen [[CáCácc pháphátt bibiểểu]u] EndEnd IfIf IfIf <ĐK><ĐK> ThenThen [[CáCácc pháphátt bibiểểu]u] ElseElse [[CáCácc pháphátt bibiểểu]u] EndEnd IfIf IfIf <ĐK><ĐK> ThenThen [[CáCácc pháphátt bibiểểu]u] ElseIfElseIf [[CáCácc pháphátt bibiểểu]u] ElseElse [[CáCácc pháphátt bibiểểu]u] EndEnd IfIf 04/07/2010 5 Windows Form programming with VB.Net 2005. 9 Select CaseSelect Case Select Case Select Case <<Tên B Tên B ếến>n> Case Case <<Giá trị Giá trị 11>> [[CáCácc pháphátt bibiểểu]u] Case Case <<Giá trị Giá trị 22>> [[CáCácc pháphátt bibiểểu]u] …… Case ElseCase Else [[CáCácc pháphátt bibiểểu]u] End SelectEnd Select Windows Form programming with VB.Net 2005. 10 VòVòng lng lặặp vp vớới Fori For For Each <For Each <Item>Item> In <In <CollectionObject>CollectionObject> [[CáCác c pháphát bit biểểu]u] [Exit For][Exit For] NextNext For For counter = startcounter = start To To end [end [Step Step stepstep]] [[CáCác c pháphát bit biểểu]u] [Exit For][Exit For] NextNext 04/07/2010 6 Windows Form programming with VB.Net 2005. 11 VòVòng lng lặặp vp vớới Do i Do ((kikiểểm tra ĐK rm tra ĐK rồồi thi thựực hic hiệện)n) Do While <ĐK đúng> dừng khi ĐK sai [Các phát biểu] [Exit Do] Loop Do Until <ĐK Sai> dừng khi ĐK đúng [Các phát biểu] [Exit Do] Loop Windows Form programming with VB.Net 2005. 12 VòVòng lng lặặp vp vớới Do i Do ((ththựực hic hiệện tn tốối thii thiểểu u 11 llầần)n) Do [Các phát biểu] [Exit Do] Loop While <ĐK đúng> ‘ dừng khi ĐK sai Do [Các phát biểu] [Exit Do] Loop Until <ĐK Sai> ‘dừng khi ĐK đúng 04/07/2010 7 Windows Form programming with VB.Net 2005. 13 Windows Form programming with VB.Net 2005. 14 VDVD Dim subfolders() As DirectoryInfo Dim getDrive As String = cboDrive.SelectedItem subfolders = New DirectoryInfo(getDrive).GetDirectories lstData.Items.Clear() Dim subfolder As DirectoryInfo For Each subfolder In subfolders lstData.Items.Add(subfolder.FullName) Next Dim allDrives() As DriveInfo = DriveInfo.GetDrives() Dim d As DriveInfo For Each d In allDrives If d.IsReady = True Then 'cboDrive.Items.Add("(" & d.VolumeLabel & ") " & d.Name) cboDrive.Items.Add(d.Name) End If Next 04/07/2010 8 Windows Form programming with VB.Net 2005. 15 Buổi 2: Contrl ClassBuổi 2: Contrl Class ¾¾PropertiesProperties:: Name,Name, Text,Text , BackColor,BackColor, Forcolor,Forcolor, Font,Font, Size,Size, Location,Location, ImageImage CanFocusCanFocus Chỉ ra khi Focus Passed controlChỉ ra khi Focus Passed control Dock, AnchorDock, Anchor Định dạng khi thiết kếĐịnh dạng khi thiết kế EnableEnable True or False True or False ((cho cho phéphép hay không)p hay không) VisibleVisible True or False True or False ((ẩẩn or hin or hiệện)n) LockedLocked True or FalseTrue or False ¾¾EventEvent:: Click,Click, MouseMouse:: MouseMove,MouseMove, MouseDown,MouseDown, MouseUpMouseUp…… Windows Form programming with VB.Net 2005. 16 Contrl ClassContrl Class ¾¾Label,Label, LinkLabelLinkLabel ¾¾ListView,ListView, TreeViewTreeView ¾¾CheckBoxCheckBox ¾¾RadioButtonRadioButton ¾¾TrackBarTrackBar ¾¾PanelPanel ¾¾GroupBox,PanelGroupBox,Panel ¾¾TextBox,RichTextBoxTextBox,RichTextBox ¾¾ DomainUpdown,DomainUpdown, NumericUpdownNumericUpdown ¾¾TabControlTabControl ¾¾PictureBoxPictureBox ¾¾ImageListImageList ¾¾TimerTimer ¾¾ScrollBarScrollBar ¾¾ProgressbarProgressbar ¾¾ToolTipToolTip ¾¾NottifyIconNottifyIcon ¾¾MaskedTextBoxMaskedTextBox 04/07/2010 9 Windows Form programming with VB.Net 2005. 17  Label: Label: a. Properties: a. Properties: Autosize: Autosize: True or FalseTrue or False  ButtonButton:: aa PropertiesProperties:: TextAlignTextAlign  LinkLabelLinkLabel:: aa PropertiesProperties:: ++ LinkColorLinkColor:: ++ ActiveLinkColorActiveLinkColor:: ++ LinkVisibleLinkVisible:: TrueTrue oror FalseFalse bb EventEvent:: +LinkClicked+LinkClicked:: SystemSystem DiagnosticsDiagnostics ProcessProcess Start("wwwStart("www vnnvnn vn")vn") Windows Form programming with VB.Net 2005. 18  TextBox:TextBox: aa PropertiesProperties:: ++MaxLengthMaxLength:: ChiềuChiềudàidài tốitối đađa ++ MultiLineMultiLine:: TrueTrue oror FalseFalse (( xuxuốốngng dòng?dòng? )) ++ PasswordCharPasswordChar:: kýký ttựự passwordpassword ++ ReadOnlyReadOnly:: ++ ScrollBarsScrollBars:: đkđk MultilineMultiline ==TrueTrue bb EventEvent:: +TextChanged: +TextChanged: The text in TextBox is ChangedThe text in TextBox is Changed + + KeyDownKeyDown, KeyUp: , KeyUp: e.KeyCodee.KeyCode + KeyPress: + KeyPress: e.KeyChare.KeyChar +MultiChanged: +MultiChanged: Value of Multiline is ChangedValue of Multiline is Changed c. Method: c. Method: Clear, Copy, Cut, Paste, Clear, Copy, Cut, Paste, FocusFocus 04/07/2010 10 Windows Form programming with VB.Net 2005. 19  ComboBox:ComboBox: a. Properties: a. Properties: + + Items:Items: xử lý on ListBox (xử lý on ListBox (Add, RemoveAt, ClearAdd, RemoveAt, Clear, , Count…) Count…) ++ SelectedIndex:SelectedIndex: chỉ mục hiện hànhchỉ mục hiện hành + SelectedItem:+ SelectedItem: Item được chọn hiện hànhItem được chọn hiện hành + Sorted:+ Sorted: True or FalseTrue or False b. Event:b. Event: ++SelectedIndexChanged:SelectedIndexChanged: Windows Form programming with VB.Net 2005. 20 :ListBox (soạn lại) :ListBox (soạn lại) aa PropertiesProperties:: ++ItemsItems:: xửxử lýlý onon ListBoxListBox ((Add,Add, RemoveAt,RemoveAt, ClearClear,, CountCount……)) ++ MultiColumnMultiColumn:: TrueTrue oror FalseFalse ++ SelectedIndexSelectedIndex:: GetGet oror SetSet vềvề chỉchỉ mụcmụchiệnhiệnhànhhành ++ SelectedItemSelectedItem:: ==ListboxListbox TextText ;; ++SortedSorted:: TrueTrue oror FalseFalse ++ SelectionModeSelectionMode:: None,None, One,One, MultiSimpleMultiSimple bb EventEvent:: +SelectedIndexChanged+SelectedIndexChanged [...]... Panel and GroupBox: Panel and GroupBox Control chủ yếu để chứa các control khác vào cùng một nhóm để thực hiện tác vụ nhằm thuận lợi cho việc quản lý công việc trong lập trình, thường là các CheckBox, RadioButton… RadioButton… CheckBox and RadioButton a Properties: Properties: + Checked: True or False (kiểm tra check) Checked: b Event: Event: + CheckedChanged: khi control được check CheckedChanged: thể... thực thi SelectedIndex được SelectedIndexChanged: ược thay đổi Windows Form programming with VB.Net 2005 37 Ví dụ: các Group control dụ: các Windows Form programming with VB.Net 2005 38 19 04/07/2010 ListView: a Properties: Properties: + Columns: Quản lý Cột của ListView Columns: Quản của + Items: Số dòng và các thành phần của dòng Items: dòng các thành phầ của dòng + View: LargeIcon, SmallIcon, Detail,... hiể + Image: Get or Set Image từ ImageList hoặc từ từ hoặ từ resource khi thiết kế thiế kế + SizeMode: cách image được hiển thị cách được hiể ImageList: a Properties: Properties: + Images: quản lý tập hợp các Image quản hợ + Images.(Index): Index của Image được set của được + Images.Count: số Image trong ImageList + ImageSize: kích thước Image (default 16x16) kích thước 16x16) Windows Form programming... thể chọn Ghi chú: một Group checkbox có thể chọn object chú: nhiề nhiều nhưng RadioButton thì chỉ chọn 1 chọn Windows Form programming with VB.Net 2005 35 Vd: Group control Windows Form programming with VB.Net 2005 36 18 04/07/2010 TabControl: a Properties: Properties: + TabCount: True or False (kiểm tra check) TabCount: + TabPages: dùng kiểm soát và tạoTabpage TabPages: + TabIndex: Trả về Index của...04/07/2010 CheckedListBox: (soạn lại) a Properties: Properties: + Items: xử lý on ListBox (Add, RemoveAt, Clear, Items: Clear, Count… Count…) b Event: Event: +SelectedIndexChanged - SelectedValueChanged: SelectedValueChanged: c Method: SetItemChecked(index, True/False) GetItemChecked(index) . 22: : Control Class Control Class – Qu Quản n lý mã lý mã llệệnhnh  Data type Cấu trúc rẽ nhánh  Cấu trúc Lặp  Khai báo biến, mảng  Các phép toán thông dụng.  Tìm hiểu Control Class Windows. GroupBoxGroupBox ControlControl chủchủ yếuyếu đểđể chứachứacáccác controlcontrol kháckhác vàovào cùngcùng mộtmộtnhómnhóm đểđể thựcthựchiệnhiệntáctác vụvụ nhằmnhằmthuậnthuậnlợilợichocho việcviệcquảnquảnl lý. dụ: : cácác Group controlc Group control 04/07/2010 20 Windows Form programming with VB.Net 2005. 39 ListView:ListView: aa PropertiesProperties:: ++ ColumnsColumns:: QuảQuảnn l lý CCộộtt củcủaaListViewListView ++ItemsItems::

Ngày đăng: 09/07/2014, 09:20

Tài liệu cùng người dùng

Tài liệu liên quan