显示拖放图像VB.NET的文本

时间:2017-10-14 12:42:52

标签: vb.net drag-and-drop

我正在为图像开发一个简单的SQL生成器。当我将图片拖到PictureBox中时,我遇到了将文本显示在文本框中的问题。我做错了吗?我想要一种情况,当我将图像拖到PictureBox中时,显示为蓝色的文本框应显示:' SELECT FROM EMPLOYEE;'。我需要帮助才能使这段代码正常工作。我的代码显示在下面。

enter image description here

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    '' picDropTarget.AllowDrop = True
    picAccept.AllowDrop = True


End Sub

Private Sub picSELECT_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picSELECT.MouseDown, picEMPLOYEE.MouseDown
    ' Start the drag if it's the left mouse button.
    If (e.Button = MouseButtons.Left) Then
        Dim source As PictureBox = DirectCast(sender, PictureBox)
        picSELECT.DoDragDrop(source.Image, DragDropEffects.Copy)
        'Added this line to show 
        'txtSQL.Text = "SELECT"
    End If
End Sub


Private Sub picAccept_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picAccept.DragEnter
    ' See if this is a copy and the data includes an image.
    If (e.Data.GetDataPresent(DataFormats.Bitmap) AndAlso
       (e.AllowedEffect And DragDropEffects.Copy) <> 0) _
    Then
        ' Allow this.
        'e.Effect = DragDropEffects.All
        e.Effect = DragDropEffects.All
    Else
        ' Don't allow any other drop.
        '   e.Effect = DragDropEffects.None
        e.Effect = DragDropEffects.Copy
    End If
End Sub

Private Sub picAccept_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picAccept.DragDrop, picSELECT.DragDrop, picEMPLOYEE.DragDrop
    Dim bm As Bitmap = DirectCast(e.Data.GetData(DataFormats.Bitmap, True), Bitmap)
    picAccept.Image = bm

End SubEnd Class

1 个答案:

答案 0 :(得分:0)

start_url

这是一个完全工作的最小样本。您可以复制/粘贴下面的文件,将文件拖放到表单底部的PictureBox中,顶部的TextBox将填充文本。

TextBox1.Text = "select from EMPLOYEES"