Giáo trình Visual Basic 4

6 388 0
Giáo trình Visual Basic 4

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

Thông tin tài liệu

Giáo trình Visual Basic

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 ảnhCó 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ìnhPictureBox1.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 DragEntersự 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ượngVí dụ: đối tượng được kéo vào TextBox2Private Sub TextBox2_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter Các câu lệnh End Subb/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.Scroll 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 DoDragDropDạng Control.DoDragDropPhương pháp này sử dụng khi bắt đầu hành động Drag-DropVí dụ 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ịuChú ý thuộc tính AlloweDrop của đối tượng nhận phải đặt trueVí dụ kéo- thả textPrivate 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 Ví dụ 2 : kéo – thả ảnhPrivate 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 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 TickPrivate 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- StartViduPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 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 . 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ìnhPictureBox1.Image = Image.FromFile(filename)Ví dụ PictureBox1.Image =

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

Từ khóa liên quan

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

Tài liệu liên quan