Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 9k
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_4
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Diagnostics.EventLog eventLog1;
  15. private System.Windows.Forms.Button button1;
  16. private AxRealAudioObjects.AxRealAudio axRealAudio1;
  17. private System.Windows.Forms.MainMenu mainMenu1;
  18. private System.Windows.Forms.MenuItem menuItem1;
  19. private System.Windows.Forms.MenuItem menuItem2;
  20. private System.Windows.Forms.MenuItem menuItem3;
  21. private System.Windows.Forms.MenuItem menuItem4;
  22. private System.Windows.Forms.ComboBox comboBox1;
  23. private System.Windows.Forms.GroupBox groupBox1;
  24. private System.Windows.Forms.Label label1;
  25. private System.Windows.Forms.GroupBox groupBox2;
  26. private System.Windows.Forms.MenuItem menuItem5;
  27. private System.Windows.Forms.MenuItem menuItem6;
  28. private System.Windows.Forms.MenuItem menuItem7;
  29. private System.Windows.Forms.MenuItem menuItem8;
  30. /// <summary>
  31. /// 必需的设计器变量。
  32. /// </summary>
  33. private System.ComponentModel.Container components = null;
  34. public Form1()
  35. {
  36. //
  37. // Windows 窗体设计器支持所必需的
  38. //
  39. InitializeComponent();
  40. //
  41. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  42. //
  43. }
  44. /// <summary>
  45. /// 清理所有正在使用的资源。
  46. /// </summary>
  47. protected override void Dispose( bool disposing )
  48. {
  49. if( disposing )
  50. {
  51. if (components != null) 
  52. {
  53. components.Dispose();
  54. }
  55. }
  56. base.Dispose( disposing );
  57. }
  58. #region Windows Form Designer generated code
  59. /// <summary>
  60. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  61. /// 此方法的内容。
  62. /// </summary>
  63. private void InitializeComponent()
  64. {
  65. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  66. this.eventLog1 = new System.Diagnostics.EventLog();
  67. this.button1 = new System.Windows.Forms.Button();
  68. this.axRealAudio1 = new AxRealAudioObjects.AxRealAudio();
  69. this.mainMenu1 = new System.Windows.Forms.MainMenu();
  70. this.menuItem1 = new System.Windows.Forms.MenuItem();
  71. this.menuItem2 = new System.Windows.Forms.MenuItem();
  72. this.menuItem3 = new System.Windows.Forms.MenuItem();
  73. this.menuItem4 = new System.Windows.Forms.MenuItem();
  74. this.menuItem5 = new System.Windows.Forms.MenuItem();
  75. this.menuItem6 = new System.Windows.Forms.MenuItem();
  76. this.menuItem7 = new System.Windows.Forms.MenuItem();
  77. this.menuItem8 = new System.Windows.Forms.MenuItem();
  78. this.comboBox1 = new System.Windows.Forms.ComboBox();
  79. this.groupBox1 = new System.Windows.Forms.GroupBox();
  80. this.label1 = new System.Windows.Forms.Label();
  81. this.groupBox2 = new System.Windows.Forms.GroupBox();
  82. ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
  83. ((System.ComponentModel.ISupportInitialize)(this.axRealAudio1)).BeginInit();
  84. this.SuspendLayout();
  85. // 
  86. // eventLog1
  87. // 
  88. this.eventLog1.SynchronizingObject = this;
  89. // 
  90. // button1
  91. // 
  92. this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  93. this.button1.Location = new System.Drawing.Point(344, 16);
  94. this.button1.Name = "button1";
  95. this.button1.Size = new System.Drawing.Size(48, 20);
  96. this.button1.TabIndex = 1;
  97. this.button1.Text = "GO";
  98. this.button1.Click += new System.EventHandler(this.button1_Click);
  99. // 
  100. // axRealAudio1
  101. // 
  102. this.axRealAudio1.Enabled = true;
  103. this.axRealAudio1.Location = new System.Drawing.Point(0, 56);
  104. this.axRealAudio1.Name = "axRealAudio1";
  105. this.axRealAudio1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axRealAudio1.OcxState")));
  106. this.axRealAudio1.Size = new System.Drawing.Size(472, 96);
  107. this.axRealAudio1.TabIndex = 2;
  108. // 
  109. // mainMenu1
  110. // 
  111. this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  112.   this.menuItem1,
  113.   this.menuItem5});
  114. // 
  115. // menuItem1
  116. // 
  117. this.menuItem1.Index = 0;
  118. this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  119.   this.menuItem2,
  120.   this.menuItem3,
  121.   this.menuItem4});
  122. this.menuItem1.Text = "网址";
  123. this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
  124. // 
  125. // menuItem2
  126. // 
  127. this.menuItem2.Index = 0;
  128. this.menuItem2.Text = "打开";
  129. this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
  130. // 
  131. // menuItem3
  132. // 
  133. this.menuItem3.Index = 1;
  134. this.menuItem3.Text = "-";
  135. // 
  136. // menuItem4
  137. // 
  138. this.menuItem4.Index = 2;
  139. this.menuItem4.Text = "退出";
  140. this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
  141. // 
  142. // menuItem5
  143. // 
  144. this.menuItem5.Index = 1;
  145. this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  146.   this.menuItem6,
  147.   this.menuItem7,
  148.   this.menuItem8});
  149. this.menuItem5.Text = "播放";
  150. // 
  151. // menuItem6
  152. // 
  153. this.menuItem6.Index = 0;
  154. this.menuItem6.Text = "暂停";
  155. this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
  156. // 
  157. // menuItem7
  158. // 
  159. this.menuItem7.Index = 1;
  160. this.menuItem7.Text = "停止";
  161. this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
  162. // 
  163. // menuItem8
  164. // 
  165. this.menuItem8.Index = 2;
  166. this.menuItem8.Text = "静音";
  167. this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
  168. // 
  169. // comboBox1
  170. // 
  171. this.comboBox1.Location = new System.Drawing.Point(56, 16);
  172. this.comboBox1.Name = "comboBox1";
  173. this.comboBox1.Size = new System.Drawing.Size(264, 20);
  174. this.comboBox1.TabIndex = 4;
  175. // 
  176. // groupBox1
  177. // 
  178. this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
  179. this.groupBox1.Name = "groupBox1";
  180. this.groupBox1.Size = new System.Drawing.Size(472, 8);
  181. this.groupBox1.TabIndex = 5;
  182. this.groupBox1.TabStop = false;
  183. // 
  184. // label1
  185. // 
  186. this.label1.Location = new System.Drawing.Point(8, 20);
  187. this.label1.Name = "label1";
  188. this.label1.Size = new System.Drawing.Size(48, 16);
  189. this.label1.TabIndex = 6;
  190. this.label1.Text = "位置:";
  191. // 
  192. // groupBox2
  193. // 
  194. this.groupBox2.Location = new System.Drawing.Point(0, 40);
  195. this.groupBox2.Name = "groupBox2";
  196. this.groupBox2.Size = new System.Drawing.Size(472, 8);
  197. this.groupBox2.TabIndex = 7;
  198. this.groupBox2.TabStop = false;
  199. // 
  200. // Form1
  201. // 
  202. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  203. this.ClientSize = new System.Drawing.Size(472, 153);
  204. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  205.   this.groupBox2,
  206.   this.label1,
  207.   this.groupBox1,
  208.   this.comboBox1,
  209.   this.axRealAudio1,
  210.   this.button1});
  211. this.Menu = this.mainMenu1;
  212. this.Name = "Form1";
  213. this.Text = "网络电台收听";
  214. ((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
  215. ((System.ComponentModel.ISupportInitialize)(this.axRealAudio1)).EndInit();
  216. this.ResumeLayout(false);
  217. }
  218. #endregion
  219. /// <summary>
  220. /// 应用程序的主入口点。
  221. /// </summary>
  222. [STAThread]
  223. static void Main() 
  224. {
  225. Application.Run(new Form1());
  226. }
  227. private void button1_Click(object sender, System.EventArgs e)
  228. {
  229. //获得播放网址
  230. string url=this.comboBox1.Text;
  231. this.axRealAudio1.Source=url;
  232. //播放
  233. this.axRealAudio1.DoPlay();
  234. }
  235. private void menuItem2_Click(object sender, System.EventArgs e)
  236. {
  237.     //新建一个Form2对象
  238. Form2 form=new Form2();
  239. //如果Form2点了确定进入
  240. if (form.ShowDialog()==DialogResult.OK)
  241. {
  242. //获得网址
  243.       this.axRealAudio1.Source=form.comboBox1.Text;
  244. //播放
  245. this.axRealAudio1.DoPlay();
  246. }
  247. }
  248. private void menuItem4_Click(object sender, System.EventArgs e)
  249. {
  250. //退出程序
  251. this.Close();
  252. Application.Exit();
  253. }
  254. private void menuItem6_Click(object sender, System.EventArgs e)
  255. {
  256. //暂停播放 
  257. this.axRealAudio1.DoPlayPause();
  258. }
  259. private void menuItem7_Click(object sender, System.EventArgs e)
  260. {
  261.    //停止播放
  262. this.axRealAudio1.DoPause();
  263. }
  264. private void menuItem8_Click(object sender, System.EventArgs e)
  265. {
  266. //判断菜单项的选中状态
  267. if (this.menuItem8.Checked==true)
  268. {
  269. //有声音
  270. this.axRealAudio1.SetMute(false);
  271. //不选中
  272. this.menuItem8.Checked=false;
  273. }
  274. else
  275. //静音
  276. this.axRealAudio1.SetMute(true);
  277. //选中
  278. this.menuItem8.Checked=true;   
  279. }
  280. }
  281. private void menuItem1_Click(object sender, System.EventArgs e)
  282. {
  283. }
  284. }
  285. }