Form1.cs
Upload User: chinafred
Upload Date: 2007-08-14
Package Size: 10127k
Code Size: 7k
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_5
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.Timer timer1;
  15. private System.Windows.Forms.Label label4;
  16. private System.Windows.Forms.Label label3;
  17. private System.Windows.Forms.Label label2;
  18. private System.Windows.Forms.TrackBar trackBar1;
  19. private System.Windows.Forms.Label label1;
  20. private System.Windows.Forms.Button button1;
  21. private System.Windows.Forms.Button button2;
  22. private System.Windows.Forms.GroupBox groupBox1;
  23. private System.ComponentModel.IContainer components;
  24. public Form1()
  25. {
  26. //
  27. // Windows 窗体设计器支持所必需的
  28. //
  29. InitializeComponent();
  30. //
  31. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  32. //
  33. }
  34. /// <summary>
  35. /// 清理所有正在使用的资源。
  36. /// </summary>
  37. protected override void Dispose( bool disposing )
  38. {
  39. if( disposing )
  40. {
  41. if (components != null) 
  42. {
  43. components.Dispose();
  44. }
  45. }
  46. base.Dispose( disposing );
  47. }
  48. #region Windows Form Designer generated code
  49. /// <summary>
  50. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  51. /// 此方法的内容。
  52. /// </summary>
  53. private void InitializeComponent()
  54. {
  55. this.components = new System.ComponentModel.Container();
  56. this.timer1 = new System.Windows.Forms.Timer(this.components);
  57. this.label4 = new System.Windows.Forms.Label();
  58. this.label3 = new System.Windows.Forms.Label();
  59. this.label2 = new System.Windows.Forms.Label();
  60. this.trackBar1 = new System.Windows.Forms.TrackBar();
  61. this.label1 = new System.Windows.Forms.Label();
  62. this.button1 = new System.Windows.Forms.Button();
  63. this.button2 = new System.Windows.Forms.Button();
  64. this.groupBox1 = new System.Windows.Forms.GroupBox();
  65. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
  66. this.groupBox1.SuspendLayout();
  67. this.SuspendLayout();
  68. // 
  69. // timer1
  70. // 
  71. this.timer1.Interval = 10;
  72. this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
  73. // 
  74. // label4
  75. // 
  76. this.label4.BackColor = System.Drawing.SystemColors.ActiveBorder;
  77. this.label4.Location = new System.Drawing.Point(144, 144);
  78. this.label4.Name = "label4";
  79. this.label4.Size = new System.Drawing.Size(56, 23);
  80. this.label4.TabIndex = 11;
  81. this.label4.Text = "100%";
  82. // 
  83. // label3
  84. // 
  85. this.label3.BackColor = System.Drawing.SystemColors.ActiveBorder;
  86. this.label3.Location = new System.Drawing.Point(18, 144);
  87. this.label3.Name = "label3";
  88. this.label3.Size = new System.Drawing.Size(112, 23);
  89. this.label3.TabIndex = 10;
  90. this.label3.Text = "窗体的透明度为:";
  91. // 
  92. // label2
  93. // 
  94. this.label2.BackColor = System.Drawing.SystemColors.ActiveBorder;
  95. this.label2.Location = new System.Drawing.Point(144, 32);
  96. this.label2.Name = "label2";
  97. this.label2.Size = new System.Drawing.Size(64, 23);
  98. this.label2.TabIndex = 9;
  99. this.label2.Text = "10毫秒";
  100. // 
  101. // trackBar1
  102. // 
  103. this.trackBar1.BackColor = System.Drawing.SystemColors.Control;
  104. this.trackBar1.Location = new System.Drawing.Point(8, 72);
  105. this.trackBar1.Maximum = 1000;
  106. this.trackBar1.Minimum = 10;
  107. this.trackBar1.Name = "trackBar1";
  108. this.trackBar1.Size = new System.Drawing.Size(214, 42);
  109. this.trackBar1.TabIndex = 8;
  110. this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
  111. this.trackBar1.Value = 10;
  112. this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
  113. // 
  114. // label1
  115. // 
  116. this.label1.BackColor = System.Drawing.SystemColors.ActiveBorder;
  117. this.label1.Location = new System.Drawing.Point(16, 32);
  118. this.label1.Name = "label1";
  119. this.label1.Size = new System.Drawing.Size(104, 16);
  120. this.label1.TabIndex = 7;
  121. this.label1.Text = "渐变时间间隔为:";
  122. // 
  123. // button1
  124. // 
  125. this.button1.BackColor = System.Drawing.SystemColors.ActiveBorder;
  126. this.button1.Location = new System.Drawing.Point(16, 192);
  127. this.button1.Name = "button1";
  128. this.button1.TabIndex = 0;
  129. this.button1.Text = "开始";
  130. this.button1.Click += new System.EventHandler(this.button1_Click);
  131. // 
  132. // button2
  133. // 
  134. this.button2.BackColor = System.Drawing.SystemColors.ActiveBorder;
  135. this.button2.Location = new System.Drawing.Point(128, 192);
  136. this.button2.Name = "button2";
  137. this.button2.TabIndex = 3;
  138. this.button2.Text = "停止";
  139. this.button2.Click += new System.EventHandler(this.button2_Click);
  140. // 
  141. // groupBox1
  142. // 
  143. this.groupBox1.BackColor = System.Drawing.SystemColors.ActiveBorder;
  144. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  145. this.label4,
  146. this.label3,
  147. this.label2,
  148. this.trackBar1,
  149. this.label1,
  150. this.button1,
  151. this.button2});
  152. this.groupBox1.Location = new System.Drawing.Point(16, 16);
  153. this.groupBox1.Name = "groupBox1";
  154. this.groupBox1.Size = new System.Drawing.Size(240, 248);
  155. this.groupBox1.TabIndex = 7;
  156. this.groupBox1.TabStop = false;
  157. // 
  158. // Form1
  159. // 
  160. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  161. this.BackColor = System.Drawing.SystemColors.ActiveBorder;
  162. this.ClientSize = new System.Drawing.Size(272, 285);
  163. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  164.   this.groupBox1});
  165. this.Name = "Form1";
  166. this.Text = "逐渐透明的窗体";
  167. ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
  168. this.groupBox1.ResumeLayout(false);
  169. this.ResumeLayout(false);
  170. }
  171. #endregion
  172. /// <summary>
  173. /// 应用程序的主入口点。
  174. /// </summary>
  175. [STAThread]
  176. static void Main() 
  177. {
  178. Application.Run(new Form1());
  179. }
  180. private void timer1_Tick(object sender, System.EventArgs e)
  181. {
  182.    //如果透明度大于0,则每次减少0.01,否则,透明度重设为1
  183. if (this.Opacity>0)
  184. {
  185. this.Opacity=(this.Opacity*100-1)/100;
  186. double p=this.Opacity*100;
  187. label4.Text=p.ToString()+"%";
  188. }
  189. else
  190. {
  191. this.Opacity=1;
  192. label4.Text="100%";
  193.             }
  194. }
  195. private void trackBar1_Scroll(object sender, System.EventArgs e)
  196. {
  197. //设置timer控件的Interval属性
  198. timer1.Interval=trackBar1.Value;
  199. label2.Text=timer1.Interval.ToString()+"毫秒";
  200. }
  201. private void button1_Click(object sender, System.EventArgs e)
  202. {  
  203. //计时器开始计时
  204. timer1.Start();
  205. }
  206. private void button2_Click(object sender, System.EventArgs e)
  207. {
  208.    //计时器停止
  209.    timer1.Stop();
  210.    //窗体透明度属性还原为1
  211.    this.Opacity=1;
  212.    label4.Text="100%";
  213. }
  214. }
  215. }