Right-click the toolbox and choose items.->Show "select toolbox items"->COM Component->WindowsMediaPlayer WMP. dllAdd
Mymediaplayer form
Public Static string Path = ""; // record the complete path of the file
String duration = ""; // time when the current file is played
Int width = 0; // The width of the playback File
Int Height = 0; // The height of the playback File
// The storage path key is the file name, and the value is the complete path
Private dictionary <string, string> pathlist = new dictionary <string, string> ();
Private void open the file toolstripmenuitem_click (Object sender, eventargs E)
{
This. openfile ();
// Clear all values in the playlist
This. listview1.items. Clear ();
// Clear the set
Pathlist. Clear ();
// Add to listview
Listviewupdate (path. getfilename (PATH), PATH );
// Play
Axwmp. url = path;
// When the playback file is opened, start the timer control to get the file time and width and height.
// If it is placed in the current position, the resulting value is 0,
// It may take some time to open a media file. The media file is waiting for opening.
Timer1.start ();
}
Private void openfile (){
// Open a file
Openfiledialog ofd = new openfiledialog ();
Dialogresult DR = ofd. showdialog ();
If (DR = dialogresult. Cancel)
{// Cancel opening
Return;
}
// Otherwise, the record opens the path
Path = ofd. filename;
}
Private void attribute toolstripmenuitem_click (Object sender, eventargs E)
{
// Record only the file name
// String S = path. getfilenamewithoutextens Ion (PATH );
// Record the file name and extension
String Ss = path. getfilename (PATH );
// Playback File Information
Musicinfo MI = new musicinfo (SS, duration, width, height );
Mi. showdialog ();