框架:.Net Framewrok 4.7.2
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.AllowDrop = True
End Sub
Private Sub PictureBox1_DragEnter(sender As Object, e As DragEventArgs) Handles PictureBox1.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Link
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub PictureBox1_DragDrop(sender As Object, e As DragEventArgs) Handles PictureBox1.DragDrop
Dim files() As String
files = e.Data.GetData(DataFormats.FileDrop)
If files.Length > 1 Then MsgBox("请只放入一个文件") : Exit Sub
Debug.Print(files(0))
PictureBox1.Image = Image.FromFile(files(0))
'image.FromFile和bitmap.FromFile都会导致该文件的占用
'比较建议用fileIO把图片加载到buff里去,可以不导致占用
'===============存储照片=====================
PictureBox1.Image.Save(Application.StartupPath & "\01.tx