2011-05-04 102 views
0

我想要設計視覺匹配對。將有兩列。左欄將顯示圖像,右欄將顯示文字標籤。用戶必須通過正確的標籤拖動圖像。如何在vb.net的picturebox中放大圖像

由於表單尺寸較小,圖片必須更小(縮略圖)。所以當用戶將鼠標懸停在圖像上時,也應該有圖像放大。用戶還應該能夠對圖像進行基本的拖放操作。

那麼我該如何實現這兩件事呢?

  1. 拖動和拖放圖片框標記

  2. PictureBox的圖像放大?

+0

這很好。如果問題沒有答案,它不會傷害你的分數。對於確實有答案的問題,最好的辦法是給他們一個獎勵(假設你已經解鎖了)。如果沒有,請再次查看已發佈的帖子,然後嘗試他們所說的話。如果沒有,那麼它是好的:) – FreeSnow 2011-05-04 18:31:19

回答

2

1)拖放圖片框[標籤:

首先,你必須將標籤設置爲TRUE(的AllowDrop屬性也可以在設計師完成):

Label.AllowDrop = True 

手柄PictureBox.MouseDown激活DragDrop:

Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ 
           Handles PictureBox1.MouseDown 

    PictureBox1.DoDragDrop(PictureBox1, DragDropEffects.All) 

End Sub 

現在,處理實驗室的DragEnter和DragDrop事件EL:

Private Sub Label1_DragDrop(ByVal sender As Object, _ 
      ByVal e As System.Windows.Forms.DragEventArgs) Handles Label1.DragDrop 

    'Get the data being dropped from e.Data and do something. 

End Sub 

Private Sub Label1_DragEnter(ByVal sender As Object, _ 
      ByVal e As System.Windows.Forms.DragEventArgs) Handles Label1.DragEnter 

    'e.Effect controls what type of DragDrop operations are allowed on the label. 
    'You can also check the type of data that is being dropped on the label here 
    'by checking e.Data. 

    e.Effect = DragDropEffects.All 
End Sub 

2)放大鼠標懸停在圖片框:

,只有它一個圖片創建一個新的窗體。這是我們要顯示放大圖像時顯示的形式,我們稱之爲Form2。現在,只需辦理縮略圖圖片框的MouseHover事件:

Private Sub PictureBox1_MouseHover(ByVal sender As Object, _ 
        ByVal e As System.EventArgs) Handles PictureBox1.MouseHover 

    'PictureBox1 is the thumbnail on the original form. 
    'PictureBox2 is the full size image on the popup form. 

    Form2.PictureBox2.ClientSize = PictureBox1.Image.Size 
    Form2.PictureBox2.Image = CType(PictureBox1.Image.Clone, Image) 
    Form2.ShowDialog() 

End Sub 

你需要玩弄你想如何處置彈出的形式的。