Resolved Identify which control in an array of controls has event.

MPIon

Well-known member
Joined
Jun 13, 2020
Messages
73
Location
England
Programming Experience
10+
I have several Media Player Controls on my form - created in code and need to identify which control has a state change.
The code is :
C#:
        static readonly AxWindowsMediaPlayer[] mediaPlayerBoxes = new AxWindowsMediaPlayer[16];
Then for each control, I add an event handler :-
C#:
mediaPlayerBoxes[i].StatusChange += MediaPlayer_StateChange;
Finally the event handler is :-
C#:
        private    void MediaPlayer_StateChange(object sender, EventArgs e)
        {
            // Get a local reference to the box that was clicked
            AxWindowsMediaPlayer player = sender as AxWindowsMediaPlayer;
            player.Ctlcontrols.pause();
        }
This does work and the video playing is paused, but I need to identify which of the Media Player controls caused the event, i.e. what is the Index into mediaPlayerBoxes.
Can't figure out how to get this.
 
Use for example WindowsThumbnailProvider class posted here: Extract thumbnail for any file in Windows

Yes, thanks - just figured how to get the thumbnail for both images and video files and it works well and is much faster drawing the screen full of thumbnails.

I actually installed WindowsAPICodePack-Shell by putting the line NuGet\Install-Package WindowsAPICodePack-Shell -Version 1.1.1 in the Package Manager Console.
Then added the references :-
C#:
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack;

Then all I needed to do to show the thumbnail was to add the code :-
C#:
        ShellFile shellFile;
        shellFile = ShellFile.FromFilePath(@<full file path>);
        pictureBox.Image = shellFile.Thumbnail.LargeBitmap;

This works like a charm.
 

Latest posts

Back
Top Bottom