Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 8k
Category:

ADO-ODBC

Development Platform:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. namespace ch5_1
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.Button button1;
  15. private System.Windows.Forms.GroupBox groupBox1;
  16. private System.Windows.Forms.TextBox textBox1;
  17. private System.Windows.Forms.Button button2;
  18. private System.Windows.Forms.MainMenu mainMenu1;
  19. private System.Windows.Forms.MenuItem menuItem1;
  20. private System.Windows.Forms.MenuItem menuItem2;
  21. private System.Windows.Forms.MenuItem menuItem3;
  22. private AxMediaPlayer.AxMediaPlayer axMediaPlayer1;
  23. /// <summary>
  24. /// 必需的设计器变量。
  25. /// </summary>
  26. private System.ComponentModel.Container components = null;
  27. public Form1()
  28. {
  29. //
  30. // Windows 窗体设计器支持所必需的
  31. //
  32. InitializeComponent();
  33. //
  34. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  35. //
  36. }
  37. /// <summary>
  38. /// 清理所有正在使用的资源。
  39. /// </summary>
  40. protected override void Dispose( bool disposing )
  41. {
  42. if( disposing )
  43. {
  44. if (components != null) 
  45. {
  46. components.Dispose();
  47. }
  48. }
  49. base.Dispose( disposing );
  50. }
  51. #region Windows Form Designer generated code
  52. /// <summary>
  53. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  54. /// 此方法的内容。
  55. /// </summary>
  56. private void InitializeComponent()
  57. {
  58. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  59. this.button1 = new System.Windows.Forms.Button();
  60. this.groupBox1 = new System.Windows.Forms.GroupBox();
  61. this.button2 = new System.Windows.Forms.Button();
  62. this.textBox1 = new System.Windows.Forms.TextBox();
  63. this.mainMenu1 = new System.Windows.Forms.MainMenu();
  64. this.menuItem1 = new System.Windows.Forms.MenuItem();
  65. this.menuItem2 = new System.Windows.Forms.MenuItem();
  66. this.menuItem3 = new System.Windows.Forms.MenuItem();
  67. this.axMediaPlayer1 = new AxMediaPlayer.AxMediaPlayer();
  68. this.groupBox1.SuspendLayout();
  69. ((System.ComponentModel.ISupportInitialize)(this.axMediaPlayer1)).BeginInit();
  70. this.SuspendLayout();
  71. // 
  72. // button1
  73. // 
  74. this.button1.Location = new System.Drawing.Point(16, 18);
  75. this.button1.Name = "button1";
  76. this.button1.TabIndex = 2;
  77. this.button1.Text = "打开";
  78. this.button1.Click += new System.EventHandler(this.button1_Click);
  79. // 
  80. // groupBox1
  81. // 
  82. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  83. this.button2,
  84. this.textBox1,
  85. this.button1});
  86. this.groupBox1.Location = new System.Drawing.Point(8, 336);
  87. this.groupBox1.Name = "groupBox1";
  88. this.groupBox1.Size = new System.Drawing.Size(456, 56);
  89. this.groupBox1.TabIndex = 4;
  90. this.groupBox1.TabStop = false;
  91. // 
  92. // button2
  93. // 
  94. this.button2.Location = new System.Drawing.Point(336, 18);
  95. this.button2.Name = "button2";
  96. this.button2.TabIndex = 5;
  97. this.button2.Text = "播放";
  98. this.button2.Click += new System.EventHandler(this.button2_Click);
  99. // 
  100. // textBox1
  101. // 
  102. this.textBox1.Location = new System.Drawing.Point(104, 20);
  103. this.textBox1.Name = "textBox1";
  104. this.textBox1.Size = new System.Drawing.Size(208, 21);
  105. this.textBox1.TabIndex = 4;
  106. this.textBox1.Text = "";
  107. // 
  108. // mainMenu1
  109. // 
  110. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  111.   this.menuItem1});
  112. // 
  113. // menuItem1
  114. // 
  115. this.menuItem1.Index = 0;
  116. this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  117.   this.menuItem2,
  118.   this.menuItem3});
  119. this.menuItem1.Text = "文件(&F)";
  120. // 
  121. // menuItem2
  122. // 
  123. this.menuItem2.Index = 0;
  124. this.menuItem2.Text = "打开(&O)";
  125. this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
  126. // 
  127. // menuItem3
  128. // 
  129. this.menuItem3.Index = 1;
  130. this.menuItem3.Text = "退出(&X)";
  131. this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
  132. // 
  133. // axMediaPlayer1
  134. // 
  135. this.axMediaPlayer1.AllowDrop = true;
  136. this.axMediaPlayer1.Location = new System.Drawing.Point(8, 0);
  137. this.axMediaPlayer1.Name = "axMediaPlayer1";
  138. this.axMediaPlayer1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMediaPlayer1.OcxState")));
  139. this.axMediaPlayer1.Size = new System.Drawing.Size(456, 320);
  140. this.axMediaPlayer1.TabIndex = 5;
  141. // 
  142. // Form1
  143. // 
  144. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  145. this.ClientSize = new System.Drawing.Size(472, 405);
  146. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  147.   this.axMediaPlayer1,
  148.   this.groupBox1});
  149. this.Menu = this.mainMenu1;
  150. this.Name = "Form1";
  151. this.Text = "媒体播放器";
  152. this.groupBox1.ResumeLayout(false);
  153. ((System.ComponentModel.ISupportInitialize)(this.axMediaPlayer1)).EndInit();
  154. this.ResumeLayout(false);
  155. }
  156. #endregion
  157. /// <summary>
  158. /// 应用程序的主入口点。
  159. /// </summary>
  160. [STAThread]
  161. static void Main() 
  162. {
  163. Application.Run(new Form1());
  164. }
  165. private void button1_Click(object sender, System.EventArgs e)
  166. {
  167. OpenFileDialog ofDialog=new OpenFileDialog();
  168. ofDialog.Filter="Window Media文件(*.asf;*.wm;*.wma)|*.asf;*.wm;*.wma|媒体播放表(*.asx;*.wax;*.m3u;*.wvx)|*.asx;*.wax;*.m3u;*.wvx|电影文件(MPEG)(*.mpeg;*.mpg)|*.mpeg;*.mpg|视频文件(*.avi;*.wmv)|*.avi;*.wmv|所有文件(*.*)|*.*";
  169. if (ofDialog.ShowDialog()==DialogResult.OK)
  170. {
  171. try
  172. {
  173. string mediaPath=ofDialog.FileName;
  174. axMediaPlayer1.FileName=mediaPath;
  175. axMediaPlayer1.Play();
  176. this.textBox1.Text=mediaPath;
  177. }
  178. catch
  179. {
  180. MessageBox.Show("无法播放此文件","警告",MessageBoxButtons.OK,MessageBoxIcon.Error);
  181. }
  182. }
  183. }
  184. protected override void OnMouseEnter( EventArgs e)
  185. {
  186. string i="";
  187. this.axMediaPlayer1.DoDragDrop(i ,DragDropEffects.None);
  188. }
  189. protected override void  OnDragEnter( DragEventArgs drgEvent)
  190. {
  191. string s=drgEvent.Data.ToString();
  192. int i=1 ;
  193. }
  194. private void button2_Click(object sender, System.EventArgs e)
  195. {
  196. if (this.textBox1.Text!="")
  197. {
  198. try
  199. {
  200. //获得文件名
  201. string mediaPath=this.textBox1.Text;
  202. //设置播放文件名
  203. axMediaPlayer1.FileName=mediaPath;
  204. //播放文件
  205. axMediaPlayer1.Play();
  206. }
  207. catch
  208. {
  209. //错误信息
  210. MessageBox.Show("无法播放此文件","警告",MessageBoxButtons.OK,MessageBoxIcon.Error);
  211. }
  212. }
  213. else
  214. {
  215. MessageBox.Show("请输入播放文件名称","警告",MessageBoxButtons.OK,MessageBoxIcon.Error); 
  216. }
  217. }
  218. private void menuItem3_Click(object sender, System.EventArgs e)
  219. {
  220. //退出程序
  221. this.Close();
  222. Application.Exit();
  223. }
  224. private void menuItem2_Click(object sender, System.EventArgs e)
  225. {
  226. OpenFileDialog ofDialog=new OpenFileDialog();
  227. //设置过滤器
  228. ofDialog.Filter="Window Media文件(*.asf;*.wm;*.wma)|*.asf;*.wm;*.wma|媒体播放表(*.asx;*.wax;*.m3u;*.wvx)|*.asx;*.wax;*.m3u;*.wvx|电影文件(MPEG)(*.mpeg;*.mpg)|*.mpeg;*.mpg|视频文件(*.avi;*.wmv)|*.avi;*.wmv|所有文件(*.*)|*.*";
  229. if (ofDialog.ShowDialog()==DialogResult.OK)
  230. {
  231. try
  232. {
  233.         //获得文件名
  234. string mediaPath=ofDialog.FileName;
  235. //设置播放文件名
  236. axMediaPlayer1.FileName=mediaPath;
  237. //播放文件
  238. axMediaPlayer1.Play();
  239. this.textBox1.Text=mediaPath;
  240. }
  241. catch
  242. {
  243. //错误信息
  244. MessageBox.Show("无法播放此文件","警告",MessageBoxButtons.OK,MessageBoxIcon.Error);
  245. }
  246. }
  247. }
  248. }
  249. }