1. Trang chủ
  2. » Công Nghệ Thông Tin

Giáo trình Visual Basic 4

6 390 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Giáo trình Visual Basic 4
Trường học University of Information Technology
Chuyên ngành Computer Science
Thể loại Giáo trình
Thành phố Ho Chi Minh City
Định dạng
Số trang 6
Dung lượng 18,34 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Giáo trình Visual Basic

Trang 1

Bai3 Các controls (tiếp theo)

1-Label:

- Dùng để thông báo các kết quả trung gian

- Giải thích chức năng các control khác

- Tính chất quan trọng hay dùng

Labele.text

+PictureBox

- Tính chất cần chú ý :

a/ Image - dùng để chứa ảnh

Có thể đưa ảnh dạng BMP,Ico,Jpg,gif bằng hai cách nạp ảnh lúc design hoặc lúc chạy chương trình

PictureBox1.Image = Image.FromFile(filename)

Ví dụ PictureBox1.Image = Image.FromFile("c:\h2.bmp")

b/ sizemode – dùng để xác định chế độ hiện ảnh trong pictuerebox

có các chế độ sau :Nomal, StrechImage, AutoSize, CenterImage, Zoom

+ Một số sự kiện cần chú ý

a/ Sự kiện DragEnter

sự kiện này xảy ra khi đối tượng của hành động Drag- Drop được kéo vào vùng của control sẽ nhận đối tượng

Ví dụ: đối tượng được kéo vào TextBox2

Private Sub TextBox2_DragEnter( ByVal sender As

System.Object, ByVal e As

System.Windows.Forms.DragEventArgs) Handles

TextBox2.DragEnter

Trang 2

Các câu lệnh

End Sub

b/Class DragDropEffects

xác định hiệu quả của hành động Drag-Drop, nó có thể có các giá trị sau:

None The drop target does not accept the data.

Copy The data is copied to the drop target.

Move The data from the drag source is moved to the drop

target

Link The data from the drag source is linked to the drop

target

Scrol

l Scrolling is about to start or is currently occurring in the drop target

All The data is copied, removed from the drag source, and

scrolled in the drop target

Ví dụ:

CDragDropEffects.Move

+ Phương pháp DoDragDrop

Dạng Control.DoDragDrop

Phương pháp này sử dụng khi bắt đầu hành động Drag-Drop

Ví dụ

Trang 3

TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy Or

DragDropEffects.Move)

Hai tham số sử dụng ở đây là :

- Đối tượng của hành động Drag-Drop

- Tác động mà nó có thể chịu

Chú ý thuộc tính AlloweDrop của đối tượng nhận phải đặt true

Ví dụ kéo- thả text

Private Sub TextBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown

TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy Or

DragDropEffects.Move)

End Sub

Private Sub TextBox2_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter

e.Effect = DragDropEffects.Move

End Sub

Private Sub TextBox2_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop

TextBox2.Text = e.Data.GetData(DataFormats.Text)

End Sub

Trang 4

Ví dụ 2 : kéo – thả ảnh

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles MyBase.Load

PictureBox2.AllowDrop = True

End Sub

Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal

e As System.Windows.Forms.MouseEventArgs) Handles

PictureBox1.MouseDown

If Not PictureBox1.Image Is Nothing Then

PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy Or DragDropEffects.Move)

Else

End If

End Sub

Private Sub PictureBox2_DragEnter(ByVal sender As System.Object, ByVal e

As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter

If e.Data.GetDataPresent(DataFormats.Bitmap) Then

e.Effect = DragDropEffects.Copy

End If

Trang 5

End Sub

Private Sub PictureBox2_DragDrop(ByVal sender As System.Object, ByVal e

As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)

End Sub

-=======================================

Timer control

+Sư kiện Tick

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Timer1.Tick

End Sub

+ Tinh chất:

- Interval : khoảng thời gian sự kiện tick xảy ra tính bằng milisecond

- Enabled : true/false

- Start

Vidu

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Timer1.Tick

Trang 6

If Label1.Visible = True Then

Label1.Visible = False

Label2.Visible = True

Else

Label1.Visible = True

Label2.Visible = False

End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Timer1.Interval = 300

Label1.Visible = True

Label2.Visible = True

Timer1.Start()

End Sub

Ngày đăng: 13/11/2012, 10:23

TỪ KHÓA LIÊN QUAN

w