Tải bản đầy đủ (.ppt) (41 trang)

hướng dẫn học visual basic 6

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (929.77 KB, 41 trang )


Visual Basic 6.0
Trần Nguyên Hương

Điều khiển ImageList,
Treeview,
ListView,
TabStrip

Điều khiển ImageList

ProjectComponentsMicrosoft
Window Common Control 6.0 (SP6)

Không nhìn thấy lúc thực thi

Dùng để chứa hình ảnh, các hình ảnh
này thường sử dụng bởi các điều khiển
khác, chẳng hạn Treeview, ListView…

Điều khiển ImageList

Đưa hình vào
ImageList:

Nhấn phải chuột vào
điều khiển ImageList
trên Form, chọn mục
Properties trên menu
ngữ cảnh


Chọn ImagesInsert
Picturechọn tệp tin
muốn thêmOK

Điều khiển Treeview

Tạo cấu trúc tương tự như công cụ
Windows Explorer của Windows

ProjectComponentsMicrosoft
Window Common Control 6.0 (SP6)

Thêm điều khiển Treeview vào Form

Điều khiển Treeview

Thêm nút cho Treeview ở thời gian
thực thi bằng phương thức Add của tập
Nodes. Cú pháp
Add([Relative], [Relationship], [key],
[Text], [SelectedImage]) as Node

Điều khiển Treeview

Thêm nút cho Treeview ở thời gian
thực thi bằng phương thức Add của tập
Nodes. Cú pháp
Add([Relative], [Relationship], [key],
[Text], [SelectedImage]) as Node
Nút khác có

quan hệ với nút
đang thêm

Điều khiển Treeview

Thêm nút cho Treeview ở thời gian
thực thi bằng phương thức Add của tập
Nodes. Cú pháp
Add([Relative], [Relationship], [key],
[Text], [SelectedImage]) as Node
Chỉ ra mối quan hệ của
nút mới (đang thêm)
với nút ở Relative
1-tvwLast: Nút mới đặt sau tất
cả các nút khác ở cùng cấp với
nút chỉ ra trong Relative
2-tvwNext: Thêm ngay sau nút
chỉ ra trong Relative
3-tvwPrevios: Thêm ngay
trước nút chỉ ra trong Relative
4-tvwChild: Nút mới là nút con
của nút chỉ ra trong Relative

Điều khiển Treeview

Thêm nút cho Treeview ở thời gian
thực thi bằng phương thức Add của tập
Nodes. Cú pháp
Add([Relative], [Relationship], [key],
[Text], [SelectedImage]) as Node

Chuỗi khoá
được thêm

Điều khiển Treeview

Thêm nút cho Treeview ở thời gian
thực thi bằng phương thức Add của tập
Nodes. Cú pháp
Add([Relative], [Relationship], [key],
[Text], [SelectedImage]) as Node
Nhãn hiển thị của
nút trong
Treeview

Điều khiển Treeview

Thêm nút cho Treeview ở thời gian
thực thi bằng phương thức Add của tập
Nodes. Cú pháp
Add([Relative], [Relationship], [key],
[Text], [SelectedImage]) as Node
Chỉ mục kết hợp
với điều khiển
ImageList để hiển
thị hình bên nút

Điều khiển Treeview

Thêm nút con cho Treeview:


VD:
Private Sub Form_Load()
Dim Node2 As Node
Set Node2 = TreeView1.Nodes.Add("Root",
tvwChild, "Nokia", "Nokia")
End sub

Điều khiển Treeview

Thêm hình ảnh vào Treeview:

Tạo ImageList1 chứa ảnh

Nhấn phải chuột vào Treeview1 trên Form,
chọn ImageList là ImageList1

Thêm số thứ tự chỉ mục của ảnh trong List
view vào phương thức Add. Ví dụ:
Set Node2 = TreeView1.Nodes.Add("Root",
tvwChild, "Nokia", "Nokia", 1)

Điều khiển Treeview

Sự kiện mở nút (dấu +): Expand
Ví dụ:

Private Sub TreeView1_Expand(ByVal Node
As MSComctlLib.Node)
Node.Image = 3


End Sub

Điều khiển Treeview

Sự kiện mở đóng (dấu -): Collapse

Ví dụ:

Private Sub TreeView1_Collapse(ByVal
Node As MSComctlLib.Node)
Node.Image = 1

End Sub

Điều khiển Treeview

Ví dụ: Tạo Treeview sau:

Điều khiển Treeview

Tạo List view để chứa ảnh

Code viết như sau:
Private Sub Form_Load()
Dim Node1, Node2, Node3, Node4, Node5 As Node
Set Node1 = TreeView1.Nodes.Add(, , "Root", "DTDD", 1)
Set Node2 = TreeView1.Nodes.Add("Root", tvwChild, "Nokia", "Nokia", 1)
Set Node3 = TreeView1.Nodes.Add("Nokia", tvwChild, "Nokia 7270",
"Nokia 7270", 2)
Set Node4 = TreeView1.Nodes.Add("Root", tvwChild, "Sony Ericsson",

"Sony Ericsson", 1)
Set Node5 = TreeView1.Nodes.Add("Root", tvwChild, "Seimens", "
Seimens", 1)
End Sub

Điều khiển Treeview
Private Sub TreeView1_Collapse(ByVal Node As
MSComctlLib.Node)
Node.Image = 1
End Sub
Private Sub TreeView1_Expand(ByVal Node As
MSComctlLib.Node)
Node.Image = 3
End Sub

Thực hành

SV tạo cây Treeview như sau:

Điều khiển ListView

ProjectComponentsMicrosoft
Window Common Control 6.0 (SP6)

Thêm điều khiển ListView vào Form
SV tìm hiểu thêm

Điều khiển TabStrip

ProjectComponentsMicrosoft

Window Common Control 6.0 (SP6)

Thêm điều khiển TabStrip vào Form

Điều khiển TabStrip

Thêm nhiều thẻ lên TabStrip: R_Click,
chọn Properties chọn Tab Nhập giá
trị cho Caption Insert Tab

VD:
SV tìm hiểu thêm

Điều khiển định thời và điều
khiển về ngày giờ

Timer

MothView

DateTimePicker

Điều khiển Timer

Định thời gian để thực hiện một công việc
nào đó

Không nhìn thấy điều khiển này lúc thực thi

Thuộc tính quan tâm:


Enabled: Cho phép kích hoạt (True) hay không
(False) kích hoạt sự kiện timer

Interval: Thiết lập chu kỳ (số Mini giây) giữa các
sự kiện. Thường khởi tạo Interval=1000 (1 giây)

Điều khiển Timer

Ví dụ: Tạo đồng hồ điện tử lúc thực thi
Run
Private Sub Timer1_Timer()
Label1.Caption = Time$
End Sub

×