Windows Media Player控件Windows Media Player是一种媒体播放器,可以播放当前最流行的音频、视频文件和大多数混合型的多媒体文件。为了便于程序的开发,Visual Studio 2005集成开发环境提供了Windows Media Player控件,并且提供了相关的属性、方法,开发者根据提供的属性、方法完全可以实现Windows Media Player播放器的所有功能。在使用Windows Media Player控件进行程序开发前,必须将Windows Media Player控件添加到工具箱中,步骤如下所示。(1)选择工具箱,并单击鼠标右键,在弹出的快捷菜单中选择“选择项”。(2)弹出“选择工具箱项”对话框,选择“COM组件”选项卡。(3)在COM组件列表中,选择名称为“Windows Media Player”,单击【确定】按钮,Windows Media Player控件添加成功,如图1所示。

图1  添加Windows Media Player控件
表1和表2介绍Windows Media Player控件提供的主要属性和方法。

表1       Windows Media Player控件主要属性及说明
另外,将Windows Media Player控件添加到窗体上,在该控件上单击鼠标右键,弹出“Windows Media Player控件属性”对话框,为Windows Media Player控件提供中文属性对话框,如图2所示。

图2  Windows Media Player控件属性设置

表2   Windows Media Player控件主要方法及说明
示例
Windows Media Player控件制作多媒体播放器
本示例利用Windows Media Player控件来实现播放视频文件。程序运行结果如图3所示。

图3  多媒体播放器
程序开发步骤如下所示。
(1)创建一个项目,命名为27_02,设置默认窗体的Text属性为“网站源代码多媒体播放器”。
(2)在窗体上添加Windows Media Player控件和3个Button控件。
(3)程序代码如下。

sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace _7_02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OpenFileDialog openFile = new OpenFileDialog();
private void button1_Click(object sender, EventArgs e)
{//本教程来自:http://www.isstudy.com
openFile.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = openFile.FileName;
}
private void button3_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.close();
}
}
}
完整程序代码如下:
★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace _7_02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OpenFileDialog openFile = new OpenFileDialog();
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
openFile.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = openFile.FileName;
}
private void button3_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.close();
}
}
}

C#中Windows Media Player控件使用实例|方法的更多相关文章

  1. C# WinForm 添加Windows Media Player 控件调试出现未能加载文件或程序集Interop.WMPLib,该怎么解决

    C# WinForm 添加Windows Media Player 控件调试出现未能加载文件或程序集Interop.WMPLib如标题,在窗体中添加Windows Media Player 控件,当调 ...

  2. ASP.NET中 TextBox 文本输入框控件的使用方法

    TextBox控件又称文本框控件,为用户提供输入文本的功能. 1.属性 TextBox控件的常用属性及说明如表1所示. 表1 TextBox控件常用属性及说明 属性 说明 AutoPostBack 获 ...

  3. iOS开发手记 - iOS9.3 UINavigationController添加后不显示storyboard中viewcontroller里的控件的解决方法

    我原先是这么做的,通常也是这么做 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSD ...

  4. Winform中用户自定义控件中外部设置子控件属性的方法

    假设我们新建立一个用户自定义控件,由一个lable1和pictureBox1组成 此时我们在外部调用该控件,然后想动态改变lable1的值,我们该怎么办? 假设实例化的用户控件名为UserContro ...

  5. C# Winform使用Windows Media Player播放多媒体整理

    一.简单使用示例步骤 1.添加Windows Media Player 组件当前是系统的 Com组件 工具箱>右键“选择项”>选择Com组件 2.控件拖拽到桌面,使用 private vo ...

  6. winform播放视频(windows media player)

    1.找到windows media player 工具箱常规下边右键,右键弹窗点击“选择项”,选择工具箱窗口点击“COM组件”,找到 Windows Media Player 勾选,点击确定 2.使用 ...

  7. 【VS开发】list控件的InsertColumn方法出错

    今天在写一个获取磁盘信息的小程序,通过list控件显示各磁盘信息.我在属性页(CPropertyPage)的构造函数中,调用list控件的InsertColumn方法,编译链接都通过了,但运行时冒出了 ...

  8. 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中的元素

    [源码下载] 背水一战 Windows 10 (76) - 控件(控件基类): Control - 基础知识, 焦点相关, 运行时获取 ControlTemplate 和 DataTemplate 中 ...

  9. 背水一战 Windows 10 (65) - 控件(WebView): 对 WebView 中的内容截图, 通过 Share Contract 分享 WebView 中的被选中的内容

    [源码下载] 背水一战 Windows 10 (65) - 控件(WebView): 对 WebView 中的内容截图, 通过 Share Contract 分享 WebView 中的被选中的内容 作 ...

随机推荐

  1. nginx缓存和flask_cache

    1.使用flask_cache的缓存功能simple模式时,直接启用可以使用,但是如果中间使用nginx代理时,就没有效果了 2.那就直接使用nginx缓存机制 http://blog.csdn.ne ...

  2. 【BZOJ】【2878】【NOI2012】迷失游乐园

    树形+基环树DP/数学期望 然而我并不会做…… 题解戳这里:http://blog.csdn.net/u011265346/article/details/46328543 好吧先考虑一个简单点的,当 ...

  3. [14] 齿轮(Gear Wheel)图形的生成算法

    顶点数据的生成 bool YfBuildGearwheelVertices ( Yreal radius, Yreal assistRadius, Yreal height, Yuint slices ...

  4. IDEA热部署基于maven的web项目

    第一步:首先先创建web项目 按照向导一步一步完成项目创建,我创建的示例项目为hotdeploddemo     第二步:设置项目的web资源         下图中的路径要修改正确,指向src/ma ...

  5. MediaPlayer 状态机 API 详解 示例

    简介 public class android.media.MediaPlayer extends Object implements VolumeAutomation 可能需要的权限: One ma ...

  6. Jmeter-Maven-Plugin高级应用:Test Results File Format-Test Results

    Test Results File Format Test Results Disabling The <testResultsTimestamp> Enabling <append ...

  7. 用10046 跟踪exp

    之前写过一个blog,Oracle expdp为什么比exp快,原理是什么,是从官方文档中获知的,如今通过10046来分析exp的过程. C:\Users\Administrator>exp L ...

  8. Timus 2005. Taxi for Programmers 题解

    The clock shows 11:30 PM. The sports programmers of the institute of maths and computer science have ...

  9. STL - 容器 - Map(一)

    MapTest.cpp #include <map> #include <string> #include <iostream> #include <algo ...

  10. 微信小程序 - 调用腾讯地图插件

    1. 登录公众号平台 https://mp.weixin.qq.com/ 2. 设置->第三方服务->添加插件->输入插件名称->申请 3. 项目中使用 3.1 app.jso ...