How to: Embed Windows Media Player on a Form
You can embed Windows Media Player in a Windows form to provide multimedia in your application. You must first add the Windows Media Player COM control to the toolbox, and then you can add the control to your application.
To Add the Windows Media Player Control to the Toolbox
On the File menu, click New Project.
In the New Project dialog box, click Windows Forms Application, and then click OK.
A new Windows Forms project opens.
Right-click the Toolbox, and click Choose Items.
Note
If you do not see the Toolbox, click Toolbox on the View menu to open it.
The Customize Toolbox Items dialog box opens.
On the COM Components tab, select the Windows Media Player check box, and then click OK.
The Windows Media Player control appears on the current Toolbox tab.
When you add the Windows Media Player control to the Toolbox, Visual Studio automatically adds references to two libraries: AxWMPLib and WMPLib. The next step is to add the control to the Windows Form.
To add the Windows Media Player control to a Windows Form
Drag the Windows Media Player control from the Toolbox to the Windows Form.
In the Properties window, set the Dock property to Fill. You can do this by clicking the center square.
Double-click the title bar of the form to add the default Load event in the Code Editor.
Add the following code to the Form_Load event handler to load a video when the application opens.
Note
The path used is a forward link that points to an on-line video. You can change the path and file name to display a different video.
axWindowsMediaPlayer1.URL = @"https://go.microsoft.com/fwlink/?LinkId=95772";
This code sets the URL of the Windows Media Player to the media file that you have specified. Windows Media Player will automatically start to play when you set the URL property because the autoStart property is true by default.
Press F5 to run the code.
When the application opens, change the size of the form to full-screen by double-clicking the title bar of the form.