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

  1. On the File menu, click New Project.

  2. In the New Project dialog box, click Windows Forms Application, and then click OK.

    A new Windows Forms project opens.

  3. Right-click the Toolbox, and click Choose Items.


    If you do not see the Toolbox, click Toolbox on the View menu to open it.

  4. The Customize Toolbox Items dialog box opens.

  5. On the COM Components tab, select the Windows Media Player check box, and then click OK.

  6. 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

  1. Drag the Windows Media Player control from the Toolbox to the Windows Form.

  2. In the Properties window, set the Dock property to Fill. You can do this by clicking the center square.

  3. Double-click the title bar of the form to add the default Load event in the Code Editor.

  4. Add the following code to the Form_Load event handler to load a video when the application opens.


    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 = 

    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.

  5. Press F5 to run the code.

  6. When the application opens, change the size of the form to full-screen by double-clicking the title bar of the form.

See Also

Other Resources

Adding Multimedia to an Application

Visual C# Guided Tour