I am trying to drop a file from windows explorer to my form and I am almost successful 🙂
After opening explorer window in shell I can drop a file to my form where I have one message box/dialog before accepting.
Problem is in fact that my messagebox with question opens in back of explorer window.
Here is a code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AllowDrop = True
End Sub
Private Sub Form1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim Files() As String
Files = e.Data.GetData(DataFormats.FileDrop)
If Files.Length > 0 Then
Dim ret As Integer = MsgBox("Would you like to upload file?" & vbNewLine & Files(0), MsgBoxStyle.OkCancel + MsgBoxStyle.Question, "Decide please")
If ret = DialogResult.OK Then
myModule.UploadF()
End If
End If
End If
End Sub
Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub btn_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_open.Click
Shell("explorer c:\", AppWinStyle.NormalFocus)
End Sub
End Class
1) Is here any way to get messagebox to pop in front of explorer window?
2) How to close opened explorer window from my program after usage?
EDIT: Solution for…
1) is to place Me.Activate before MsgBox!
2) for that I still don’t find a solution.
Try this:
Add a Dialog to your project. (Found in the list of addable things like form, class etc).
Add a label to it and change the text in the constructor.
In the Dialogs paint event add this:
Then use this dialog instead of MsgBox, it should provide what you need.
It’s somewhat of a workaround but it should work.
Edit:
Right, found a better solution.
Add this to the code written in this question before calling MsgBox:
And you will be fine.