Bài giảng Lập trình ứng dụng Windows Form in VB.NET 2005 - 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

pdf21 trang | Chuyên mục: Visual Basic 6.0 | Chia sẻ: dkS00TYs | Lượt xem: 2043 | Lượt tải: 3download
Tóm tắt nội dung Bài giảng Lập trình ứng dụng Windows Form in VB.NET 2005 - Buổi 2: Control Class - Quản lý mã lệnh, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
gramming 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 :

File đính kèm:

  • pdfBài giảng Lập trình ứng dụng Windows Form in VB.NET 2005 - Buổi 2_Control Class - Quản lý mã lệnh.pdf
Tài liệu liên quan