⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AxWindowsApplication1
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		int FileSum=0;
		ArrayList swfFiles=new ArrayList( );
		private AxShockwaveFlashObjects.AxShockwaveFlash axFlash;
		private System.Windows.Forms.ListBox lstList;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnRemove;
		private System.Windows.Forms.Button btnNext;
		private System.Windows.Forms.Button btnPlayPause;
		/// <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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.axFlash = new AxShockwaveFlashObjects.AxShockwaveFlash();
            this.lstList = new System.Windows.Forms.ListBox();
            this.btnAdd = new System.Windows.Forms.Button();
            this.btnRemove = new System.Windows.Forms.Button();
            this.btnNext = new System.Windows.Forms.Button();
            this.btnPlayPause = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.axFlash)).BeginInit();
            this.SuspendLayout();
            // 
            // axFlash
            // 
            this.axFlash.Enabled = true;
            this.axFlash.Location = new System.Drawing.Point(232, 16);
            this.axFlash.Name = "axFlash";
            this.axFlash.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axFlash.OcxState")));
            this.axFlash.Size = new System.Drawing.Size(424, 312);
            this.axFlash.TabIndex = 0;
            // 
            // lstList
            // 
            this.lstList.BackColor = System.Drawing.SystemColors.Control;
            this.lstList.ItemHeight = 15;
            this.lstList.Location = new System.Drawing.Point(27, 31);
            this.lstList.Name = "lstList";
            this.lstList.Size = new System.Drawing.Size(160, 154);
            this.lstList.TabIndex = 1;
            this.lstList.SelectedIndexChanged += new System.EventHandler(this.lstList_SelectedIndexChanged);
            // 
            // btnAdd
            // 
            this.btnAdd.Location = new System.Drawing.Point(11, 226);
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(85, 30);
            this.btnAdd.TabIndex = 2;
            this.btnAdd.Text = "添加";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnRemove
            // 
            this.btnRemove.Location = new System.Drawing.Point(107, 226);
            this.btnRemove.Name = "btnRemove";
            this.btnRemove.Size = new System.Drawing.Size(96, 30);
            this.btnRemove.TabIndex = 3;
            this.btnRemove.Text = "移除";
            this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);
            // 
            // btnNext
            // 
            this.btnNext.Location = new System.Drawing.Point(11, 267);
            this.btnNext.Name = "btnNext";
            this.btnNext.Size = new System.Drawing.Size(85, 30);
            this.btnNext.TabIndex = 4;
            this.btnNext.Text = "下一个";
            this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
            // 
            // btnPlayPause
            // 
            this.btnPlayPause.Location = new System.Drawing.Point(107, 267);
            this.btnPlayPause.Name = "btnPlayPause";
            this.btnPlayPause.Size = new System.Drawing.Size(96, 30);
            this.btnPlayPause.TabIndex = 5;
            this.btnPlayPause.Text = "播放";
            this.btnPlayPause.Click += new System.EventHandler(this.btnPlayPause_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
            this.ClientSize = new System.Drawing.Size(672, 344);
            this.Controls.Add(this.btnPlayPause);
            this.Controls.Add(this.btnNext);
            this.Controls.Add(this.btnRemove);
            this.Controls.Add(this.btnAdd);
            this.Controls.Add(this.lstList);
            this.Controls.Add(this.axFlash);
            this.MinimumSize = new System.Drawing.Size(500, 300);
            this.Name = "Form1";
            this.Text = "Flash播放器";
            this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.axFlash)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		//添加文件到列表,允许一次添加多个文件
		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			//
			OpenFileDialog Dlg=new OpenFileDialog( );
			Dlg.Multiselect=true;
			Dlg.Filter="Flash文档(*.swf)|*.swf|所有文件(*.*)|*.*";
			Dlg.ShowDialog( );
			FileSum+=Dlg.FileNames.Length;
			for(int i=0;i<Dlg.FileNames.Length;i++)
			{
				swfFiles.Add(Dlg.FileNames[i]);    //保存完整的文件路径
				int GetFileNameIndex=Dlg.FileNames[i].LastIndexOf("\\");    //仅取文件
				string GetFileName=Dlg.FileNames[i].Substring(GetFileNameIndex+1);
				lstList.Items.Add(GetFileName);
			}
			//Dlg.OpenFile( );
		}

		private void btnRemove_Click(object sender, System.EventArgs e)
		{
			//判断当前列表是否为空或未选中任何选项
			if(lstList.Items.Count==0||lstList.SelectedIndex==-1)
				return;
			//如不保存索引值(下标),在移除所选项后,“SelectIndex”将为-1
			int Idx=lstList.SelectedIndex;    //保存当前选项索引值
			lstList.Items.Remove(lstList.SelectedItem);    //移除列表中的当前选项
			swfFiles.Remove(swfFiles[Idx]);    //移除相应路径选项
			FileSum--;    //文件总数减1
		}

		private void btnNext_Click(object sender, System.EventArgs e)
		{
			//axFlash.Refresh( );
			if(lstList.SelectedIndex<lstList.Items.Count-1)
			{
				lstList.SelectedIndex++;
			}
			else
			{
				lstList.SelectedIndex=0;
				//axFlash.Movie=Convert.ToString(swfFiles[lstList.SelectedIndex]);
				//axFlash.Play( );
				//btnPlayPause.Text="暂停";
			}
				axFlash.Movie=Convert.ToString(swfFiles[lstList.SelectedIndex]);
				axFlash.Play();
				btnPlayPause.Text="暂停";
		}

		private void btnPlayPause_Click(object sender, System.EventArgs e)
		{
			//判断当前列表是否为空或未选中任何选项
			if(lstList.Items.Count==0||lstList.SelectedIndex==-1)
				return;
			if(btnPlayPause.Text=="播放")
			{
				axFlash.Movie=Convert.ToString(swfFiles[lstList.SelectedIndex]);
				axFlash.Play( );
				axFlash.Playing=true;
				btnPlayPause.Text="暂停";
			}
			else
			{
				axFlash.Playing=false;
				btnPlayPause.Text="播放";
			}
		}

		private void Form1_SizeChanged(object sender, System.EventArgs e)
		{
			axFlash.Width=this.Width-216;
			axFlash.Height=this.Height-84;
			lstList.Height=this.Height-164;
			btnAdd.Top=this.Height-124;
			btnRemove.Top=this.Height-124;
			btnNext.Top=this.Height-92;
			btnPlayPause.Top=this.Height-92;
		}

		private void lstList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//axFlash.Movie=Convert.ToString(swfFiles[lstList.SelectedIndex]);
			//axFlash.Stop( );
			//axFlash.StopPlay( );
			btnPlayPause.Text="播放";
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//axFlash.Movie="E:\\CHENYIN\\成语故事\\百姓点灯.swf";
			//axFlash.Play( );
		}

		//private void button1_Click(object sender, System.EventArgs e)
		//{
		//	label1.Text=lstList.SelectedIndex.ToString ( )+"  "+FileSum.ToString( )
		//		+"  "+swfFiles.Count
		//		+Convert.ToString(swfFiles[lstList.SelectedIndex]);
		//	
		//}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -