Vb.net 图像拖放-如何获取图像
我正在尝试编写一个程序,允许用户将图像从任何文件夹拖放到表单的图片框中。我得到了拖放部分,但我不知道如何将图像存储在变量上,以便能够拖放到picturebox上。以下是我到目前为止的情况:Vb.net 图像拖放-如何获取图像,vb.net,image,Vb.net,Image,我正在尝试编写一个程序,允许用户将图像从任何文件夹拖放到表单的图片框中。我得到了拖放部分,但我不知道如何将图像存储在变量上,以便能够拖放到picturebox上。以下是我到目前为止的情况: Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent()
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
AddHandler picCategoryImage.DragDrop, AddressOf picCategoryImage_DragDrop
AddHandler picCategoryImage.DragEnter, AddressOf picCategoryImage_DragEnter
End Sub
Private Sub picCategoryImage_DragDrop(sender As Object, e As DragEventArgs) Handles picCategoryImage.DragDrop
Dim picbox As PictureBox = CType(sender, PictureBox)
Dim g As Graphics = picbox.CreateGraphics()
g.DrawImage(CType(e.Data.GetData(DataFormats.Bitmap), Image), New Point(0, 0))
End Sub
Private Sub picCategoryImage_DragEnter(sender As Object, e As DragEventArgs) Handles picCategoryImage.DragEnter
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
我哪里出错了?您需要在DragEnter事件中使用
数据格式.FileDrop
而不是数据格式.Bitmap
。在DragDrop中,打开从e.Data.GetData()
获取的文件名:
您需要在DragEnter事件中使用
DataFormats.FileDrop
而不是DataFormats.Bitmap
。在DragDrop中,打开从e.Data.GetData()
获取的文件名:
您需要在DragEnter事件中使用
DataFormats.FileDrop
而不是DataFormats.Bitmap
。在DragDrop中,打开从e.Data.GetData()
获取的文件名:
您需要在DragEnter事件中使用
DataFormats.FileDrop
而不是DataFormats.Bitmap
。在DragDrop中,打开从e.Data.GetData()
获取的文件名:
你所说的任何文件夹中的
图像是什么意思
你指的是碰巧是图像文件的文件吗?如果它是一个实际的图像,它从哪里来/是如何被丢弃的?你所说的任何文件夹中的图像是什么意思?如果它是一个实际的图像,它从哪里来/是如何被丢弃的?你所说的任何文件夹中的图像是什么意思?如果它是一个实际的图像,它从哪里来/是如何被丢弃的?你所说的任何文件夹中的图像是什么意思?如果它是一幅真实的图像,它是从哪里来的/怎么掉下来的?
Private Sub picCategoryImage_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles picCategoryImage.DragDrop
Dim picbox As PictureBox = CType(sender, PictureBox)
Dim files() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
If files.Length <> 0 Then
Try
picbox.Image = Image.FromFile(files(0))
Catch ex As Exception
MessageBox.Show("Problem opening file ")
End Try
End If
End Sub
Private Sub picCategoryImage_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles picCategoryImage.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
picCategoryImage.AllowDrop = True