how to drag and drop on an AxWindowsMediaPlayer screen C#

I just created a media player using the AxWindowsMediaPlayer component, I would like to drag and drop audio and video files onto the screen, I would like that once dropped, the files play automatically, but I don't know how do ... it's really important help me

Upvotes: 1

Views: 164

Answers (1)

Simple
Simple

Reputation: 865

Assuming it's a Windows Forms C# Project you can do the following:

namespace WMP_DragDropTest
{
    public partial class Form1 : System.Windows.Forms.Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void panel1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop))
            {
                var file = (string[])e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop);
                string URL = file[0];
                this.axWindowsMediaPlayer1.URL = URL;
            }
        }

        private void panel1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(System.Windows.Forms.DataFormats.FileDrop))
            {
                e.Effect = System.Windows.Forms.DragDropEffects.Link;
            }
        }
    }
}

Note that the Windows Media Player Control has no Drag events, so as in the code above you need to wrap it in a Panel and set its property AllowDrop to True from the Designer also you need to set its events for DragDrop and DragEnter.

Upvotes: 0

Related Questions