Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 5k
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 ch1_14
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.NotifyIcon notifyIcon1;
  15. private System.Windows.Forms.Button button1;
  16. private System.Windows.Forms.ContextMenu contextMenu1;
  17. private System.Windows.Forms.MenuItem menuItem1;
  18. private System.Windows.Forms.Label label1;
  19. private System.ComponentModel.IContainer components;
  20. public Form1()
  21. {
  22. //
  23. // Windows 窗体设计器支持所必需的
  24. //
  25. InitializeComponent();
  26. //
  27. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  28. //
  29. }
  30. /// <summary>
  31. /// 清理所有正在使用的资源。
  32. /// </summary>
  33. protected override void Dispose( bool disposing )
  34. {
  35. if( disposing )
  36. {
  37. if (components != null) 
  38. {
  39. components.Dispose();
  40. }
  41. }
  42. base.Dispose( disposing );
  43. }
  44. #region Windows Form Designer generated code
  45. /// <summary>
  46. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  47. /// 此方法的内容。
  48. /// </summary>
  49. private void InitializeComponent()
  50. {
  51. this.components = new System.ComponentModel.Container();
  52. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  53. this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
  54. this.contextMenu1 = new System.Windows.Forms.ContextMenu();
  55. this.menuItem1 = new System.Windows.Forms.MenuItem();
  56. this.button1 = new System.Windows.Forms.Button();
  57. this.label1 = new System.Windows.Forms.Label();
  58. this.SuspendLayout();
  59. // 
  60. // notifyIcon1
  61. // 
  62. this.notifyIcon1.ContextMenu = this.contextMenu1;
  63. this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
  64. this.notifyIcon1.Text = "这是一个演示将程序图标停放在任务栏上的测试程序";
  65. this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);
  66. // 
  67. // contextMenu1
  68. // 
  69. this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  70.  this.menuItem1});
  71. // 
  72. // menuItem1
  73. // 
  74. this.menuItem1.Index = 0;
  75. this.menuItem1.Text = "退出";
  76. this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
  77. // 
  78. // button1
  79. // 
  80. this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  81. this.button1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  82. this.button1.Location = new System.Drawing.Point(8, 152);
  83. this.button1.Name = "button1";
  84. this.button1.Size = new System.Drawing.Size(256, 64);
  85. this.button1.TabIndex = 0;
  86. this.button1.Text = "将窗体隐藏到系统任务栏上";
  87. this.button1.Click += new System.EventHandler(this.button1_Click);
  88. // 
  89. // label1
  90. // 
  91. this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
  92. this.label1.Location = new System.Drawing.Point(8, 40);
  93. this.label1.Name = "label1";
  94. this.label1.Size = new System.Drawing.Size(256, 64);
  95. this.label1.TabIndex = 1;
  96. this.label1.Text = "    这是一个演示将程序图标停放在任务栏上的测试程序。";
  97. // 
  98. // Form1
  99. // 
  100. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  101. this.ClientSize = new System.Drawing.Size(280, 229);
  102. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  103.   this.label1,
  104.   this.button1});
  105. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  106. this.Name = "Form1";
  107. this.Text = "演示图标程序";
  108. this.Resize += new System.EventHandler(this.Form1_Resize);
  109. this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
  110. this.ResumeLayout(false);
  111. }
  112. #endregion
  113. /// <summary>
  114. /// 应用程序的主入口点。
  115. /// </summary>
  116. [STAThread]
  117. static void Main() 
  118. {
  119. Application.Run(new Form1());
  120. }
  121. private void button1_Click(object sender, System.EventArgs e)
  122. {
  123.     this.Visible=false;
  124. //使得notifyIcon控件显示在任务栏上
  125. this.notifyIcon1.Visible=true;
  126. }
  127. private void notifyIcon1_Click(object sender, System.EventArgs e)
  128. {
  129. //显示窗体
  130. this.Visible=true;
  131. }
  132. private void menuItem1_Click(object sender, System.EventArgs e)
  133. {
  134. //退出程序
  135. this.notifyIcon1.Visible=false;
  136. this.Close();
  137. Application.Exit();
  138. }
  139. private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  140. {
  141. //指示取消关闭事件
  142. e.Cancel=true;
  143. this.Visible=false;
  144. ////使得notifyIcon控件显示在任务栏上
  145. this.notifyIcon1.Visible=true;
  146. }
  147. private void Form1_Resize(object sender, System.EventArgs e)
  148. {
  149. this.Visible=false;
  150. ////使得notifyIcon控件显示在任务栏上
  151. this.notifyIcon1.Visible=true;
  152. }
  153. }
  154. }