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
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.
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ả ả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
End Sub
----------------------------
Private Sub PictureBox2_DragDrop(ByVal sender As System.Object, ByVal e