1.打開vs2019新建一個(gè)窗體項(xiàng)目,選用框架.net framework4.7.2
2.在【工具箱】里隨便選中一個(gè)控件,右鍵單擊它
看到圖片中的【選擇項(xiàng)】了嘛,單擊它,打開添加組件的一個(gè)窗體
在添加組件窗體中的【COM組件】中找到【W(wǎng)indow Media Player】組件并勾選,然后【確定】
3.可以看到我們的【工具箱】中多了一個(gè)控件,Window Media Player
4.我們先在自定義窗體上添加一個(gè)標(biāo)簽,文本內(nèi)容為打開文件;再給窗體添加一個(gè)視頻控件,將標(biāo)簽控件的Dock屬性設(shè)置為Up,視頻控件的Dock屬性設(shè)置為Fill
5.給標(biāo)簽添加點(diǎn)擊事件文章來源:http://www.zghlxwxcb.cn/news/detail-530778.html
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BLSPBFQ
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void toolStripLabel_打開文件_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
if (openFileDialog.FileName.Length != 0)
{
axWindowsMediaPlayer.URL=openFileDialog.FileName;
Text = $"正在播放{openFileDialog.FileName}";
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
?6.重新生成并運(yùn)行即可,其也可以用于播放音頻文章來源地址http://www.zghlxwxcb.cn/news/detail-530778.html
到了這里,關(guān)于C#制作簡易視頻播放器的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!