📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Player
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnmp3;
private System.Windows.Forms.Button btnmovie;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.axWindowsMediaPlayer1 = new AxWMPLib.AxWindowsMediaPlayer();
this.label1 = new System.Windows.Forms.Label();
this.btnmp3 = new System.Windows.Forms.Button();
this.btnmovie = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).BeginInit();
this.SuspendLayout();
//
// axWindowsMediaPlayer1
//
this.axWindowsMediaPlayer1.Enabled = true;
this.axWindowsMediaPlayer1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.axWindowsMediaPlayer1.Location = new System.Drawing.Point(96, 0);
this.axWindowsMediaPlayer1.Name = "axWindowsMediaPlayer1";
this.axWindowsMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWindowsMediaPlayer1.OcxState")));
this.axWindowsMediaPlayer1.Size = new System.Drawing.Size(568, 368);
this.axWindowsMediaPlayer1.TabIndex = 0;
this.axWindowsMediaPlayer1.Enter += new System.EventHandler(this.axWindowsMediaPlayer1_Enter);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 4;
this.label1.Text = "选择文件:";
//
// btnmp3
//
this.btnmp3.Location = new System.Drawing.Point(8, 88);
this.btnmp3.Name = "btnmp3";
this.btnmp3.TabIndex = 5;
this.btnmp3.Text = "音频文件";
this.btnmp3.Click += new System.EventHandler(this.btnmp3_Click);
//
// btnmovie
//
this.btnmovie.Location = new System.Drawing.Point(8, 144);
this.btnmovie.Name = "btnmovie";
this.btnmovie.TabIndex = 6;
this.btnmovie.Text = "视频文件";
this.btnmovie.Click += new System.EventHandler(this.btnmovie_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(664, 368);
this.Controls.Add(this.btnmovie);
this.Controls.Add(this.btnmp3);
this.Controls.Add(this.label1);
this.Controls.Add(this.axWindowsMediaPlayer1);
this.Name = "Form1";
this.Text = "媒体播放器";
((System.ComponentModel.ISupportInitialize)(this.axWindowsMediaPlayer1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnmp3_Click(object sender, System.EventArgs e)
{
OpenFileDialog urlDialog = new OpenFileDialog();
urlDialog.AddExtension = true;
urlDialog.CheckFileExists = true;
urlDialog.CheckPathExists = true;
//the next sentence must be in single line
urlDialog.Filter = "MP3文件(*.mp3)|*.mp3|WindowMediaVideo(*.wmv)|*.wmv|WAV文件(*.wav)|*.wav";
urlDialog.DefaultExt = "*.mp3";
if(urlDialog.ShowDialog() == DialogResult.OK)
{
string mp3url = urlDialog.FileName;
this.axWindowsMediaPlayer1.URL = mp3url;
}
}
private void btnmovie_Click(object sender, System.EventArgs e)
{
OpenFileDialog urlDialog = new OpenFileDialog();
urlDialog.AddExtension = true;
urlDialog.CheckFileExists = true;
urlDialog.CheckPathExists = true;
//the next sentence must be in single line
urlDialog.Filter = "Audio文件(*.avi)|*.avi|RealAudio(*.rmvb)|*.rmvb|视频剪辑(*.MPG)|*.MPG|所有文件 (*.*)|*.*";
urlDialog.DefaultExt = "*.avi";
if(urlDialog.ShowDialog() == DialogResult.OK)
{
string movieurl=urlDialog.FileName;
this.axWindowsMediaPlayer1.URL=movieurl;
}
}
private void axWindowsMediaPlayer1_Enter(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -