Form1.cs
上传用户:chinafred
上传日期:2007-08-14
资源大小:10127k
文件大小:11k
源码类别:

数据库编程

开发平台:

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 ch9_1
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private AxAgentObjects.AxAgent axAgent1;
  15. private AgentObjects.IAgentCtlCharacterEx Character;
  16. private string agent;
  17. private System.Windows.Forms.ComboBox comboBox1;
  18. private System.Windows.Forms.TextBox textBox1;
  19. private System.Windows.Forms.GroupBox groupBox1;
  20. private System.Windows.Forms.Label label1;
  21. private System.Windows.Forms.NumericUpDown numericUpDown1;
  22. private System.Windows.Forms.Label label2;
  23. private System.Windows.Forms.GroupBox groupBox2;
  24. private System.Windows.Forms.Button chooseButton;
  25. private System.Windows.Forms.Button activeButton;
  26. private System.Windows.Forms.Button confirmButton;
  27. private System.Windows.Forms.Button exitButton;
  28. private System.Windows.Forms.MainMenu mainMenu1;
  29. /// <summary>
  30. /// 必需的设计器变量。
  31. /// </summary>
  32. private System.ComponentModel.Container components = null;
  33. public Form1()
  34. {
  35. //
  36. // Windows 窗体设计器支持所必需的
  37. //
  38. InitializeComponent();
  39. // comboBox1.SelectedIndex=0;
  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.axAgent1 = new AxAgentObjects.AxAgent();
  67. this.activeButton = new System.Windows.Forms.Button();
  68. this.comboBox1 = new System.Windows.Forms.ComboBox();
  69. this.textBox1 = new System.Windows.Forms.TextBox();
  70. this.groupBox1 = new System.Windows.Forms.GroupBox();
  71. this.label2 = new System.Windows.Forms.Label();
  72. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  73. this.label1 = new System.Windows.Forms.Label();
  74. this.confirmButton = new System.Windows.Forms.Button();
  75. this.groupBox2 = new System.Windows.Forms.GroupBox();
  76. this.chooseButton = new System.Windows.Forms.Button();
  77. this.exitButton = new System.Windows.Forms.Button();
  78. this.mainMenu1 = new System.Windows.Forms.MainMenu();
  79. ((System.ComponentModel.ISupportInitialize)(this.axAgent1)).BeginInit();
  80. this.groupBox1.SuspendLayout();
  81. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  82. this.groupBox2.SuspendLayout();
  83. this.SuspendLayout();
  84. // 
  85. // axAgent1
  86. // 
  87. this.axAgent1.Enabled = true;
  88. this.axAgent1.Location = new System.Drawing.Point(248, 320);
  89. this.axAgent1.Name = "axAgent1";
  90. this.axAgent1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axAgent1.OcxState")));
  91. this.axAgent1.Size = new System.Drawing.Size(32, 32);
  92. this.axAgent1.TabIndex = 0;
  93. this.axAgent1.ClickEvent += new AxAgentObjects._AgentEvents_ClickEventHandler(this.axAgent1_ClickEvent);
  94. this.axAgent1.DblClick += new AxAgentObjects._AgentEvents_DblClickEventHandler(this.axAgent1_DblClick);
  95. // 
  96. // activeButton
  97. // 
  98. this.activeButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  99. this.activeButton.Location = new System.Drawing.Point(40, 72);
  100. this.activeButton.Name = "activeButton";
  101. this.activeButton.Size = new System.Drawing.Size(75, 24);
  102. this.activeButton.TabIndex = 1;
  103. this.activeButton.Text = "激活精灵";
  104. this.activeButton.Click += new System.EventHandler(this.activeButton_Click);
  105. // 
  106. // comboBox1
  107. // 
  108. this.comboBox1.Items.AddRange(new object[] {
  109.    "Genie",
  110.    "Merlin",
  111.    "Peedy",
  112.    "Robby"});
  113. this.comboBox1.Location = new System.Drawing.Point(120, 32);
  114. this.comboBox1.Name = "comboBox1";
  115. this.comboBox1.Size = new System.Drawing.Size(121, 20);
  116. this.comboBox1.TabIndex = 2;
  117. this.comboBox1.Text = "Genie";
  118. // 
  119. // textBox1
  120. // 
  121. this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;
  122. this.textBox1.Multiline = true;
  123. this.textBox1.Name = "textBox1";
  124. this.textBox1.Size = new System.Drawing.Size(320, 96);
  125. this.textBox1.TabIndex = 3;
  126. this.textBox1.Text = "请写入您的提示内容";
  127. // 
  128. // groupBox1
  129. // 
  130. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  131. this.label2,
  132. this.numericUpDown1,
  133. this.label1});
  134. this.groupBox1.Location = new System.Drawing.Point(24, 120);
  135. this.groupBox1.Name = "groupBox1";
  136. this.groupBox1.Size = new System.Drawing.Size(272, 72);
  137. this.groupBox1.TabIndex = 6;
  138. this.groupBox1.TabStop = false;
  139. this.groupBox1.Text = "设置定时提醒";
  140. // 
  141. // label2
  142. // 
  143. this.label2.Location = new System.Drawing.Point(200, 32);
  144. this.label2.Name = "label2";
  145. this.label2.Size = new System.Drawing.Size(56, 23);
  146. this.label2.TabIndex = 2;
  147. this.label2.Text = "分钟";
  148. // 
  149. // numericUpDown1
  150. // 
  151. this.numericUpDown1.Location = new System.Drawing.Point(104, 32);
  152. this.numericUpDown1.Minimum = new System.Decimal(new int[] {
  153.    1,
  154.    0,
  155.    0,
  156.    0});
  157. this.numericUpDown1.Name = "numericUpDown1";
  158. this.numericUpDown1.Size = new System.Drawing.Size(80, 21);
  159. this.numericUpDown1.TabIndex = 1;
  160. this.numericUpDown1.Value = new System.Decimal(new int[] {
  161.  1,
  162.  0,
  163.  0,
  164.  0});
  165. // 
  166. // label1
  167. // 
  168. this.label1.Location = new System.Drawing.Point(56, 32);
  169. this.label1.Name = "label1";
  170. this.label1.Size = new System.Drawing.Size(32, 23);
  171. this.label1.TabIndex = 0;
  172. this.label1.Text = "等待";
  173. // 
  174. // confirmButton
  175. // 
  176. this.confirmButton.Enabled = false;
  177. this.confirmButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  178. this.confirmButton.Location = new System.Drawing.Point(64, 344);
  179. this.confirmButton.Name = "confirmButton";
  180. this.confirmButton.Size = new System.Drawing.Size(75, 24);
  181. this.confirmButton.TabIndex = 7;
  182. this.confirmButton.Text = "确定";
  183. this.confirmButton.Click += new System.EventHandler(this.confirmButton_Click);
  184. // 
  185. // groupBox2
  186. // 
  187. this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
  188. this.chooseButton,
  189. this.comboBox1,
  190. this.activeButton});
  191. this.groupBox2.Location = new System.Drawing.Point(24, 208);
  192. this.groupBox2.Name = "groupBox2";
  193. this.groupBox2.Size = new System.Drawing.Size(272, 104);
  194. this.groupBox2.TabIndex = 8;
  195. this.groupBox2.TabStop = false;
  196. this.groupBox2.Text = "选择精灵";
  197. // 
  198. // chooseButton
  199. // 
  200. this.chooseButton.Enabled = false;
  201. this.chooseButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  202. this.chooseButton.Location = new System.Drawing.Point(152, 72);
  203. this.chooseButton.Name = "chooseButton";
  204. this.chooseButton.Size = new System.Drawing.Size(75, 24);
  205. this.chooseButton.TabIndex = 3;
  206. this.chooseButton.Text = "重新选择";
  207. this.chooseButton.Click += new System.EventHandler(this.chooseButton_Click);
  208. // 
  209. // exitButton
  210. // 
  211. this.exitButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  212. this.exitButton.Location = new System.Drawing.Point(176, 344);
  213. this.exitButton.Name = "exitButton";
  214. this.exitButton.Size = new System.Drawing.Size(75, 24);
  215. this.exitButton.TabIndex = 9;
  216. this.exitButton.Text = "退出";
  217. this.exitButton.Click += new System.EventHandler(this.exitButton_Click);
  218. // 
  219. // Form1
  220. // 
  221. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  222. this.ClientSize = new System.Drawing.Size(320, 397);
  223. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  224.   this.exitButton,
  225.   this.groupBox2,
  226.   this.confirmButton,
  227.   this.groupBox1,
  228.   this.textBox1,
  229.   this.axAgent1});
  230. this.Menu = this.mainMenu1;
  231. this.Name = "Form1";
  232. this.Text = "精灵提醒";
  233. ((System.ComponentModel.ISupportInitialize)(this.axAgent1)).EndInit();
  234. this.groupBox1.ResumeLayout(false);
  235. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  236. this.groupBox2.ResumeLayout(false);
  237. this.ResumeLayout(false);
  238. }
  239. #endregion
  240. /// <summary>
  241. /// 应用程序的主入口点。
  242. /// </summary>
  243. [STAThread]
  244. static void Main() 
  245. {
  246. Application.Run(new Form1());
  247. }
  248. private void activeButton_Click(object sender, System.EventArgs e)
  249. {
  250. //得到精灵名称
  251. string s=comboBox1.SelectedItem.ToString();
  252. this.agent=s;
  253. //根据用户的选择导入精灵
  254. switch (s)
  255. case "Genie":
  256. //导入具体的精灵 
  257. axAgent1.Characters.Load("Genie", (object)"GENIE.ACS");
  258. Character = axAgent1.Characters["Genie"];
  259. break;
  260. case "Merlin":
  261. axAgent1.Characters.Load("Merlin", (object)"MERLIN.ACS");
  262. Character = axAgent1.Characters["Merlin"]; 
  263. break;
  264. case "Peedy":
  265. axAgent1.Characters.Load("Peedy", (object)"PEEDY.ACS");
  266. Character = axAgent1.Characters["Peedy"];
  267. break;
  268. case "Robby":
  269. axAgent1.Characters.Load("Robby", (object)"ROBBY.ACS");
  270. Character = axAgent1.Characters["Robby"]; 
  271. break;
  272. }
  273. //显示精灵 
  274. Character.Show(null);
  275. //改变其他button的状态
  276.         this.activeButton.Enabled=false;
  277. this.chooseButton.Enabled=true;
  278. this.confirmButton.Enabled=true;
  279. }
  280. private void chooseButton_Click(object sender, System.EventArgs e)
  281. {
  282. //精灵动作停止
  283. this.Character.Stop(null);
  284. //卸载导入的精灵
  285. this.axAgent1.Characters.Unload(agent);
  286. //改变其他按钮的状态
  287. this.activeButton.Enabled=true;
  288. this.chooseButton.Enabled=false;
  289. this.confirmButton.Enabled=false;
  290. }
  291. private void axAgent1_ClickEvent(object sender, AxAgentObjects._AgentEvents_ClickEvent e)
  292. {
  293.        //显示主窗体
  294. this.Visible=true;
  295. }
  296. private void confirmButton_Click(object sender, System.EventArgs e)
  297. {
  298. //隐藏窗体
  299. this.Visible=false;
  300. //隐藏精灵
  301. this.Character.Hide(null);
  302. //确定隐藏时间
  303. int i=(int)this.numericUpDown1.Value*60*1000;
  304. //等待
  305. System.Threading.Thread.Sleep(1000);
  306. //显示精灵
  307. this.Character.Show(null);
  308. string s=this.textBox1.Text;
  309. //精灵说话
  310. Character.Speak(s,null);
  311. }
  312. private void exitButton_Click(object sender, System.EventArgs e)
  313. {
  314.     //关闭窗体,退出程序
  315. this.Close();
  316. Application.Exit();
  317. }
  318. private void axAgent1_DblClick(object sender, AxAgentObjects._AgentEvents_DblClickEvent e)
  319. {
  320. this.Visible=true;
  321. }
  322. }
  323. }