winform播放视频
时间: 2023-07-29 22:12:56 浏览: 62
您好!对于在WinForm中播放视频,您可以使用Windows Media Player控件来实现。以下是一个简单的示例代码:
```csharp
using System;
using System.Windows.Forms;
namespace VideoPlayerApp
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
// 设置Windows Media Player控件的位置和大小
axWindowsMediaPlayer1.Location = new System.Drawing.Point(10, 10);
axWindowsMediaPlayer1.Size = new System.Drawing.Size(400, 300);
// 指定要播放的视频文件路径
axWindowsMediaPlayer1.URL = "D:\\video.mp4";
}
}
}
```
请确保您已经将Windows Media Player ActiveX控件添加到工具箱中,并将其拖放到您的WinForm界面上。这样就可以在运行时播放指定路径的视频文件。
希望对您有所帮助!如果您还有其他问题,请随时提问。