Picture Drag and drop reset

xion.truth

New member
Joined
Oct 15, 2007
Messages
1
Programming Experience
1-3
I have a form with a user control on it. When i click a button the user control is loaded. The coding from the user control allows the user to drag and drop a picture into a picturebox1. The code works great however if i close the user control and re-open it, it stops workiing.

When i debug it looks the same, working or not working, it finds the file, shows it assigned to the to the picturebox, however when the function ends it will clear the values. It will only clear the values if the userControl was reloaded and not if its the first time. here is the code below.

Thanks
xion

VB.NET:
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements IMessageFilter.PreFilterMessage

        If m.Msg = WM_DROPFILES Then
            Dim nfiles As Integer = DragQueryFile(m.WParam, -1, Nothing, 0) '<- this code to handle multiple dropped files.. not really neccesary for this example
            Dim i As Integer
            For i = 0 To nfiles
                Dim sb As StringBuilder = New StringBuilder(256)
                DragQueryFile(m.WParam, i, sb, 256)
                HandleDroppedFiles(sb.ToString())
            Next
            DragFinish(m.WParam)
            Return True
        End If
        Return False
        ploc = ploc
    End Function '<-- if i reload the form the function clears ploc and picturebox1 values

    Public Sub HandleDroppedFiles(ByVal file As String)
        If Len(file) > 0 Then
            LoadPicture(file)

        End If
    End Sub

    Public Function LoadPicture(ByVal File As String) As Boolean
        If Len(File) > 0 Then
            Dim b As Bitmap = New Bitmap(File)

            PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            PictureBox1.Image = Image.FromFile(File)
            ploc = File


        End If
        Me.Refresh()

        Return True

        Return False
    End Function
    Public Sub pictures()

    End Sub

    Private Declare Function DragAcceptFiles Lib "shell32.dll" (ByVal hwnd As IntPtr, ByVal accept As Boolean) As Long

    Private Declare Function DragQueryFile Lib "shell32.dll" (ByVal hdrop As IntPtr, ByVal ifile As Integer, ByVal fname As StringBuilder, ByVal fnsize As Integer) As Integer

    Private Declare Sub DragFinish Lib "Shell32.dll" (ByVal hdrop As IntPtr)

    Public Const WM_DROPFILES As Integer = 563
 
Back
Top