Lập trình Lập trình VB.Net 2005 - Control Class - Quản lý mã lệnh

Properties:: +HotTracking::True or False ((hiển thị Hyperlink) +Nodes::kiểm soát các Node trong một Tree +Index: chỉ Index of a Image in ImageList + ImageList::Danh sáchImage có thểhiển thị + SelectedNode::Giữ Node hiện hànhđược chọn +CheckBoxes::có thêm check box trongTreeView

pdf21 trang | Chia sẻ: maiphuongtl | Lượt xem: 2092 | Lượt tải: 1download
Bạn đang xem trước 20 trang tài liệu Lập trình Lập trình VB.Net 2005 - Control Class - Quản lý mã lệnh, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
†04/07/2010 †1 Windows Form programming with VB.Net 2005. 1 Buổi 2: Control Class – Quản lý mã lệnh ™ 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 type Size Range Short 2 bytes -32,768 Æ 32,767 UShort 2 bytes 0 Æ 65,535 Integer 4 bytes -2,147,483,648 Æ 2,147,483,647 UInteger 4 bytes 0 Æ 4,294,967,295 Long 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 ULong 8 bytes 0 Æ 18,446,744,073,709,551,615 Single 4 bytes -3.4028235E+38 Æ 3.4028235E+38 Double 8 bytes -1.79769313486231E+308 Æ 1.79769313486231E+308 Decimal 16 bytes values up to +/-79,228 x 1024 Byte 1 byte 0 Æ 255 (no negative numbers) SByte 1 byte -128 Æ 127 Char 16 bytes Any Unicode symbol in the range 0–65,535 String 2 bytes per character 0 to 2 billion Unicode characters Boolean 2 bytes True or False Date 8 bytes January 1, 0001, Æ December 31, 9999 Object 4 bytes Can cpntain data of any type †04/07/2010 †2 Windows Form programming with VB.Net 2005. 3 Biến: * Khai báo biến: Dim as Vd: Dim x as Integer * Khai báo mảng: Dim (so) as Vd: Dim Diem(4) as Integer ReDim diem(5) Windows Form programming with VB.Net 2005. 4 Các phép toán: Phéo toán Mô tả + Cộng − Trừ * Nhân / Chia \ Chia lấy phần nguyên Mod Chia lấy phần dư ^ Lũy thừa & Nối 2 chuỗi †04/07/2010 †3 Windows Form programming with VB.Net 2005. 5 Các phép toán rút gọn: Operation + X = X + 6 X += 6 - X = X – 6 X -= 6 * X = X * 6 X *= 6 / X = X / 6 X /= 6 \ X = X \ 6 X \= 6 ^ X = X ^ 6 X ^= 6 (&) X = X & "ABC" X &= "ABC" Windows Form programming with VB.Net 2005. 6 Toán tử so sánh: Operator Mô tả > Lớn hơn < Nhỏ hơn >= Lớn hơn hoặc bằng <= Lớn hơn hoặc bằng = Bằng Khác †04/07/2010 †4 Windows Form programming with VB.Net 2005. 7 Phép toán logic Operator Mô tả Not Phủ định And True And True = True (TH còn lại là False) Or False Or False = False(TH Còn lại là True) Xor = True 2 vế SS phủ định nhau= False 2 vế SS Không phủ định nhau Windows Form programming with VB.Net 2005. 8 Cấu trúc rẽ nhánh: If Then [Các phát biểu] End If If Then [Các phát biểu] Else [Các phát biểu] End If If Then [Các phát biểu] ElseIf [Các phát biểu] Else [Các phát biểu] End If †04/07/2010 †5 Windows Form programming with VB.Net 2005. 9 Select Case Select Case Case [Các phát biểu] Case [Các phát biểu] ….. Case Else [Các phát biểu] End Select Windows Form programming with VB.Net 2005. 10 Vòng lặp với For For Each In [Các phát biểu] [Exit For] Next For counter = start To end [Step step] [Các phát biểu] [Exit For] Next †04/07/2010 †6 Windows Form programming with VB.Net 2005. 11 Vòng lặp với Do (kiểm tra ĐK rồi thực hiện) Do While dừng khi ĐK sai [Các phát biểu] [Exit Do] Loop Do Until dừng khi ĐK đúng [Các phát biểu] [Exit Do] Loop Windows Form programming with VB.Net 2005. 12 Vòng lặp với Do (thực hiện tối thiểu 1 lần) Do [Các phát biểu] [Exit Do] Loop While ‘ dừng khi ĐK sai Do [Các phát biểu] [Exit Do] Loop Until ‘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 VD 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 Class ¾Properties: Name, Text, BackColor, Forcolor, Font, Size, Location, Image CanFocus Chỉ ra khi Focus Passed control Dock, Anchor Định dạng khi thiết kế Enable True or False (cho phép hay không) Visible True or False (ẩn or hiện) Locked True or False ¾Event: Click, Mouse: MouseMove, MouseDown, MouseUp…. Windows Form programming with VB.Net 2005. 16 Contrl Class ¾Label, LinkLabel ¾ListView, TreeView ¾CheckBox ¾RadioButton ¾TrackBar ¾Panel ¾GroupBox,Panel ¾TextBox,RichTextBox ¾ DomainUpdown, NumericUpdown ¾TabControl ¾PictureBox ¾ImageList ¾Timer ¾ScrollBar ¾Progressbar ¾ToolTip ¾NottifyIcon ¾MaskedTextBox †04/07/2010 †9 Windows Form programming with VB.Net 2005. 17 ™ Label: a. Properties: Autosize: True or False ™ Button: a. Properties: TextAlign ™ LinkLabel: a. Properties: + LinkColor: + ActiveLinkColor: + LinkVisible: True or False b. Event: +LinkClicked: System.Diagnostics.Process.Start("www.vnn.vn") Windows Form programming with VB.Net 2005. 18 ™ TextBox: a. Properties: + MaxLength: Chiều dài tối đa + MultiLine: True or False ( xuống dòng? ) + PasswordChar: ký tự password + ReadOnly: + ScrollBars: đk Multiline = True b. Event: +TextChanged: The text in TextBox is Changed + KeyDown, KeyUp: e.KeyCode + KeyPress: e.KeyChar +MultiChanged: Value of Multiline is Changed c. Method: Clear, Copy, Cut, Paste, Focus †04/07/2010 †10 Windows Form programming with VB.Net 2005. 19 ™ ComboBox: a. Properties: + Items: xử lý on ListBox (Add, RemoveAt, Clear, Count…) + SelectedIndex: chỉ mục hiện hành + SelectedItem: Item được chọn hiện hành + Sorted: True or False b. Event: +SelectedIndexChanged: Windows Form programming with VB.Net 2005. 20 ™:ListBox (soạn lại) a. Properties: + Items: xử lý on ListBox (Add, RemoveAt, Clear, Count…) + MultiColumn: True or False + SelectedIndex: Get or Set về chỉ mục hiện hành + SelectedItem: = Listbox.Text ; + Sorted: True or False + SelectionMode: None, One, MultiSimple b. Event: +SelectedIndexChanged †04/07/2010 †11 Windows Form programming with VB.Net 2005. 21 ™CheckedListBox: (soạn lại) a. Properties: + Items: xử lý on ListBox (Add, RemoveAt, Clear, Count…) b. Event: +SelectedIndexChanged - SelectedValueChanged: c. Method: SetItemChecked(index, True/False) GetItemChecked(index) = True/False Windows Form programming with VB.Net 2005. 22 Ví dụ: †04/07/2010 †12 Windows Form programming with VB.Net 2005. 23 DomainUpdown and NumericUpdown: ™ DomainUpdown a. Properties: + Items: tập hợp các nội dung hiển thị + Sorted: True or False + Wrap: True or False (xoay vòng) + SelectedItem+ SelectedIndex: (= ComboBox) ™ NumericUpdown: a. Properties: + Maximum, Minimun: giá trị [Min…Max] + Value: trả về giá trị hiện hành + Increment: ấn định giá trị tăng (default=1) Windows Form programming with VB.Net 2005. 24 Vi dụ: DomainUpdown and NumericUpdown: †04/07/2010 †13 Windows Form programming with VB.Net 2005. 25 ™ DateTimePicker : 8. MonthCalendar: a. Properties: + SelectionRange.Start, SelectionRange.End: Get or Set DateTime khi ứng dụng được chạy a. Properties: + Text: Thông tin ngày tháng năm được chọn + Value.obj: obj ở đây là: day, month, year, Date, Hour, minute, second, millisecond, DayofYearm, DayofWeek….. + Format: Long, Short, Time, Custom + CustomFormat: dùng khi Format là Custom + ShowUpDown: Giống dạng …Updown ở trên Windows Form programming with VB.Net 2005. 26 Ví dụ: DateTimePicker & MonthCalendar: †04/07/2010 †14 Windows Form programming with VB.Net 2005. Value Description d Day of month as digits with no leading zero for single-digit days. dd Day of month as digits with leading zero for single-digit days. ddd Day of week as a three-letter abbreviation. dddd Day of week as its full name. M Month as digits with no leading zero for single-digit months. MM Month as digits with leading zero for single-digit months. MMM Month as a three-letter abbreviation. MMMM Month as its full name. y Year as last two digits, with no leading zero for years less than 10. yy Year as last two digits, with a leading zero for years less than 10. yyyy Year represented by full four digits. Windows Form programming with VB.Net 2005. Value Description h Hours with no leading zero for single-digit hours; 12-hour clock hh Hours with leading zero for single-digit hours; 12-hour clock H Hours with no leading zero for single-digit hours; 24-hour clock HH Hours with leading zero for single-digit hours; 24-hour clock m Minutes with no leading zero for single-digit minutes mm Minutes with leading zero for single-digit minutes s Seconds with no leading zero for single-digit seconds ss Seconds with leading zero for single-digit seconds t One character time marker string, such as A or P tt Multicharacter time marker string, such as AM or PM †04/07/2010 †15 Windows Form programming with VB.Net 2005. 29 ™ Timer a. Properties: + Interval: mô tả chu kỳ thời gian in Milliseconds giữa mỗi nhịp (tick) của timer (default=100) b. Event: + Tick: thực khi thời gian Interval trôi qua và timer timer is enabled b. Method: + Start: Starts the timer when timer is enabled + Stop: Stops the timer if it has been already started ™ ImageList: a. Properties: + Images: lưu danh sách các Image Windows Form programming with VB.Net 2005. 30 ™ PictureBox: ™ ImageList: a. Properties: + Images: quản lý tập hợp các Image + Images.(Index): Index của Image được set + Images.Count: số Image trong ImageList + ImageSize: kích thước Image (default 16x16) a.Properties + ImageLocation: đường dẫn 1 Image cần hiển thị + Image: Get or Set Image từ ImageList hoặc từ resource khi thiết kế + SizeMode: cách image được hiển thị †04/07/2010 †16 Windows Form programming with VB.Net 2005. 31 Vd: Timer - PictureBox - ImageList: Windows Form programming with VB.Net 2005. 32 9. ProgressBar a. Properties: + Maximum: Max Value of ProgresBar + Minimum: Min Value of ProgresBar + Value: Vị trí hiện tại của cursor trong ProgresBar + Step: mô tả giá trị = PerformStep method b. Method: + Increment: di chuyển vị trí of ProgresBar = cách tăng value +PerformStep: di chuyển vị trí of ProgresBar = cách chỉ ra value in Step †04/07/2010 †17 Windows Form programming with VB.Net 2005. 33 9. TrackBar a. Properties: + Maximum: Max Value of ProgresBar + Minimum: Min Value of ProgresBar + Value: Vị trí hiện tại của cursor trong ProgresBar + TickStyle: định dạng TrackBar b. Event: + Scorll: Thực thi khi di chuyển TrackBar +Valuechanged: Thực thi khi Value is changed Windows Form programming with VB.Net 2005. 34 Vd: TrackBar: †04/07/2010 †18 Windows Form programming with VB.Net 2005. 35 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… ™ CheckBox and RadioButton a. Properties: + Checked: True or False (kiểm tra check) b. Event: + CheckedChanged: khi control được check ™ Ghi chú: một Group checkbox có thể chọn object nhiều nhưng RadioButton thì chỉ chọn 1 Windows Form programming with VB.Net 2005. 36 Vd: Group control †04/07/2010 †19 Windows Form programming with VB.Net 2005. 37 TabControl: a. Properties: + TabCount: True or False (kiểm tra check) + TabPages: dùng kiểm soát và tạoTabpage + TabIndex: Trả về Index của TabPage (0…n-1) + SelectedIndex: Get or Set TabIndex hiện hành b. Event: + SelectedIndexChanged: thực thi SelectedIndex được thay đổi Windows Form programming with VB.Net 2005. 38 Ví dụ: các Group control †04/07/2010 †20 Windows Form programming with VB.Net 2005. 39 ListView: a. Properties: + Columns: Quản lý Cột của ListView + Items: Số dòng và các thành phần của dòng + View: LargeIcon, SmallIcon, Detail, List + Group: dùng chia nhóm theo View + Multiselect: True or False + Sorting: (Ascending, Descending) b. Event: + ColumnClick: thực thi khi cột được click c. Method: + Clear: xóa tấ cả các Item trong ListView Windows Form programming with VB.Net 2005. 40 TreeView: a. Properties: +HotTracking:True or False (hiển thị Hyperlink) + Nodes: kiểm soát các Node trong một Tree +ImageIndex: chỉ ra Index of a Image in ImageList + ImageList: Danh sách Image có thể hiển thị + SelectedNode: Giữ Node hiện hành được chọn + CheckBoxes: có thêm check box trong TreeView b. Method: + CollapseAll, ExpandAll: che lấp, mở rộng + GetNodeCount: trả về số Node of Tree †04/07/2010 †21 Windows Form programming with VB.Net 2005. 41 TreeView: c. Event: + AfterCheck, BeforeCheck: + AfterCollapse, BeforeCollapse: + AfterExpand, BeforeExpand: + AfterSelect, BeforeSelect :

Các file đính kèm theo tài liệu này:

  • pdfvb_net_2005_b2_5073.pdf
Tài liệu liên quan