源码可在这下载,把swf改为rar解压
首先拖拽到Form上的东西
pictureBox,button,和openFileDialog button的单击事件: private void button1_Click(object sender, EventArgs e) { this.openFileDialog1.ShowDialog(); video.VideoName = this.openFileDialog1.FileName; video.PlayVideo(video.VideoName, this.pictureBox1); }
设置openFileDialog的Filter属性,要在对话框中显示的文件筛选器,例如,"文本文件(*.txt)|*.txt|所有文件(*.*)||*.*",这个格式为,1|2|3|4|5|6,单数为显示,双数为执行,比如“文本文件(*.txt)|*.txt”,这样打开了对话框后就显示出文本文件(*.txt),而后边的*.txt则会把.txt的文件显示
这个播放功能的全部代码如下
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace videotest { public partial class Form1 : Form { Media.VideoPlay video = new Media.VideoPlay(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.openFileDialog1.ShowDialog(); video.VideoName = this.openFileDialog1.FileName; video.PlayVideo(video.VideoName, this.pictureBox1); } } }
需要注意的是要引入一个第3方的Media.dll
源码可在这下载,把swf改为rar解压