DragDrop on custom Button class

pcpc9

New member
Joined
Mar 7, 2012
Messages
2
Programming Experience
Beginner
I created a class inheriting from the button class. I'm trying to make it run some code when I drag a file on the button.


The Problem: Nothing happens, like if the event was never raised


I tried the event on a regular button and it works just fine. But when I try it in my custom class it doesn't work


DragEnter, DragLeave and Click work though.




Here's part of my code :


VB.NET:
Public Class soundButton
    Inherits Button


    Public spacing As Integer = 6
    Public soundFile As String
    Public sound As Microsoft.DirectX.AudioVideoPlayback.Audio


    Private Sub DragEffect(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
        End If


    End Sub


    Private Sub soundButton_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop


        MsgBox("It works")


        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
 
        //Do stuff

        End If


    End Sub


    Public Sub New(ByVal row, ByVal column)
        Me.Width = Form1.soundButtonRef.Width
        Me.Height = Form1.soundButtonRef.Height
        Me.Location = New Point(row * (Me.Width + spacing) + spacing + 6, column * (Me.Height + spacing) + spacing + 6)
        Me.AllowDrop = True


        Form1.Controls.Add(Me)
        Me.Show()


    End Sub


End Class



Thanks for your help
 
The code you posted here should work just fine, i did a quick test and it appears to work as well... whatever that is causing the event to not be raised is most likely somewhere else in your code...
 
It works now. It was due to Studio not being set to x86 as a development target. In the express version you can't modify it directly but there is a workaround. Hard to find, i'm glad I got it
 
Back
Top