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 ch1_4
  8. {
  9. /// <summary>
  10. /// Form1 的摘要说明。
  11. /// </summary>
  12. public class Form1 : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.GroupBox groupBox1;
  15. private System.Windows.Forms.Button button1;
  16. private System.Windows.Forms.NumericUpDown numericUpDown4;
  17. private System.Windows.Forms.NumericUpDown numericUpDown3;
  18. private System.Windows.Forms.NumericUpDown numericUpDown2;
  19. private System.Windows.Forms.Label label5;
  20. private System.Windows.Forms.Label label4;
  21. private System.Windows.Forms.Label label3;
  22. private System.Windows.Forms.Label label2;
  23. private System.Windows.Forms.NumericUpDown numericUpDown1;
  24. /// <summary>
  25. /// 必需的设计器变量。
  26. /// </summary>
  27. private System.ComponentModel.Container components = null;
  28. public Form1()
  29. {
  30. //
  31. // Windows 窗体设计器支持所必需的
  32. //
  33. InitializeComponent();
  34. //
  35. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  36. //
  37. }
  38. /// <summary>
  39. /// 清理所有正在使用的资源。
  40. /// </summary>
  41. protected override void Dispose( bool disposing )
  42. {
  43. if( disposing )
  44. {
  45. if (components != null) 
  46. {
  47. components.Dispose();
  48. }
  49. }
  50. base.Dispose( disposing );
  51. }
  52. #region Windows Form Designer generated code
  53. /// <summary>
  54. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  55. /// 此方法的内容。
  56. /// </summary>
  57. private void InitializeComponent()
  58. {
  59. this.groupBox1 = new System.Windows.Forms.GroupBox();
  60. this.button1 = new System.Windows.Forms.Button();
  61. this.numericUpDown4 = new System.Windows.Forms.NumericUpDown();
  62. this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
  63. this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
  64. this.label5 = new System.Windows.Forms.Label();
  65. this.label4 = new System.Windows.Forms.Label();
  66. this.label3 = new System.Windows.Forms.Label();
  67. this.label2 = new System.Windows.Forms.Label();
  68. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  69. this.groupBox1.SuspendLayout();
  70. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit();
  71. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
  72. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
  73. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  74. this.SuspendLayout();
  75. // 
  76. // groupBox1
  77. // 
  78. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  79. this.button1,
  80. this.numericUpDown4,
  81. this.numericUpDown3,
  82. this.numericUpDown2,
  83. this.label5,
  84. this.label4,
  85. this.label3,
  86. this.label2,
  87. this.numericUpDown1});
  88. this.groupBox1.Location = new System.Drawing.Point(24, 24);
  89. this.groupBox1.Name = "groupBox1";
  90. this.groupBox1.Size = new System.Drawing.Size(312, 256);
  91. this.groupBox1.TabIndex = 1;
  92. this.groupBox1.TabStop = false;
  93. this.groupBox1.Text = "设置窗体大小";
  94. // 
  95. // button1
  96. // 
  97. this.button1.Location = new System.Drawing.Point(24, 192);
  98. this.button1.Name = "button1";
  99. this.button1.Size = new System.Drawing.Size(56, 23);
  100. this.button1.TabIndex = 9;
  101. this.button1.Text = "设置";
  102. this.button1.Click += new System.EventHandler(this.button1_Click);
  103. // 
  104. // numericUpDown4
  105. // 
  106. this.numericUpDown4.Location = new System.Drawing.Point(232, 136);
  107. this.numericUpDown4.Maximum = new System.Decimal(new int[] {
  108.    1000,
  109.    0,
  110.    0,
  111.    0});
  112. this.numericUpDown4.Name = "numericUpDown4";
  113. this.numericUpDown4.Size = new System.Drawing.Size(40, 21);
  114. this.numericUpDown4.TabIndex = 8;
  115. this.numericUpDown4.Value = new System.Decimal(new int[] {
  116.  300,
  117.  0,
  118.  0,
  119.  0});
  120. // 
  121. // numericUpDown3
  122. // 
  123. this.numericUpDown3.Location = new System.Drawing.Point(96, 136);
  124. this.numericUpDown3.Maximum = new System.Decimal(new int[] {
  125.    1000,
  126.    0,
  127.    0,
  128.    0});
  129. this.numericUpDown3.Name = "numericUpDown3";
  130. this.numericUpDown3.Size = new System.Drawing.Size(40, 21);
  131. this.numericUpDown3.TabIndex = 7;
  132. this.numericUpDown3.Value = new System.Decimal(new int[] {
  133.  300,
  134.  0,
  135.  0,
  136.  0});
  137. // 
  138. // numericUpDown2
  139. // 
  140. this.numericUpDown2.Location = new System.Drawing.Point(232, 56);
  141. this.numericUpDown2.Maximum = new System.Decimal(new int[] {
  142.    1000,
  143.    0,
  144.    0,
  145.    0});
  146. this.numericUpDown2.Name = "numericUpDown2";
  147. this.numericUpDown2.Size = new System.Drawing.Size(40, 21);
  148. this.numericUpDown2.TabIndex = 6;
  149. this.numericUpDown2.Value = new System.Decimal(new int[] {
  150.  300,
  151.  0,
  152.  0,
  153.  0});
  154. // 
  155. // label5
  156. // 
  157. this.label5.Location = new System.Drawing.Point(152, 136);
  158. this.label5.Name = "label5";
  159. this.label5.Size = new System.Drawing.Size(72, 23);
  160. this.label5.TabIndex = 5;
  161. this.label5.Text = "最大高度";
  162. // 
  163. // label4
  164. // 
  165. this.label4.Location = new System.Drawing.Point(16, 136);
  166. this.label4.Name = "label4";
  167. this.label4.Size = new System.Drawing.Size(72, 23);
  168. this.label4.TabIndex = 4;
  169. this.label4.Text = "最小高度";
  170. // 
  171. // label3
  172. // 
  173. this.label3.Location = new System.Drawing.Point(152, 56);
  174. this.label3.Name = "label3";
  175. this.label3.Size = new System.Drawing.Size(72, 23);
  176. this.label3.TabIndex = 3;
  177. this.label3.Text = "最大宽度";
  178. // 
  179. // label2
  180. // 
  181. this.label2.Location = new System.Drawing.Point(16, 56);
  182. this.label2.Name = "label2";
  183. this.label2.Size = new System.Drawing.Size(72, 23);
  184. this.label2.TabIndex = 2;
  185. this.label2.Text = "最小宽度";
  186. // 
  187. // numericUpDown1
  188. // 
  189. this.numericUpDown1.ForeColor = System.Drawing.SystemColors.WindowText;
  190. this.numericUpDown1.Location = new System.Drawing.Point(96, 56);
  191. this.numericUpDown1.Maximum = new System.Decimal(new int[] {
  192.    1000,
  193.    0,
  194.    0,
  195.    0});
  196. this.numericUpDown1.Name = "numericUpDown1";
  197. this.numericUpDown1.Size = new System.Drawing.Size(40, 21);
  198. this.numericUpDown1.TabIndex = 1;
  199. this.numericUpDown1.Value = new System.Decimal(new int[] {
  200.  300,
  201.  0,
  202.  0,
  203.  0});
  204. // 
  205. // Form1
  206. // 
  207. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  208. this.AutoScroll = true;
  209. this.ClientSize = new System.Drawing.Size(360, 325);
  210. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  211.   this.groupBox1});
  212. this.Name = "Form1";
  213. this.Text = "设置窗体大小";
  214. this.groupBox1.ResumeLayout(false);
  215. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit();
  216. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
  217. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
  218. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  219. this.ResumeLayout(false);
  220. }
  221. #endregion
  222. /// <summary>
  223. /// 应用程序的主入口点。
  224. /// </summary>
  225. [STAThread]
  226. static void Main() 
  227. {
  228. Application.Run(new Form1());
  229. }
  230. private void button1_Click(object sender, System.EventArgs e)
  231. {
  232. int widthmin=System.Decimal.ToInt32(numericUpDown1.Value);
  233. int heightmin=System.Decimal.ToInt32(numericUpDown3.Value);
  234.             int widthmax=System.Decimal.ToInt32(numericUpDown2.Value);
  235. int heightmax=System.Decimal.ToInt32(numericUpDown4.Value);
  236. DialogResult dr,dr2;
  237. if (widthmin>widthmax)
  238. {
  239.     dr = MessageBox.Show("设置的最小宽度比最大宽度还大,如果坚持此设置,窗体的宽度将固定为最大宽度",
  240. "警告",MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
  241.     //根据对话框的返回值进行处理,如果是Cancel则将值的设置还原
  242. if (dr == DialogResult.OK)
  243. {
  244.     //没有任何处理
  245. }
  246. else if (dr==DialogResult.Cancel)
  247. {
  248. numericUpDown1.Value=300;
  249. numericUpDown2.Value=300;
  250.                }
  251. }
  252.     if (heightmin>heightmax)
  253. {
  254.     dr2 = MessageBox.Show("设置的最小高度比最大高度还大,如果坚持此设置,窗体的高度将固定为最大高度",
  255. "警告",MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
  256.     //根据对话框的返回值进行处理,如果是Cancel则将值的设置还原
  257. if (dr2== DialogResult.OK)
  258. {
  259.     //没有任何处理
  260. }
  261. else if (dr2==DialogResult.Cancel)
  262. {
  263. numericUpDown3.Value=300;
  264. numericUpDown4.Value=300;
  265. }
  266. }
  267. widthmin=System.Decimal.ToInt32(numericUpDown1.Value);
  268.     heightmin=System.Decimal.ToInt32(numericUpDown3.Value);
  269. widthmax=System.Decimal.ToInt32(numericUpDown2.Value);
  270. heightmax=System.Decimal.ToInt32(numericUpDown4.Value);
  271. Size p1= new Size(widthmin,heightmin);
  272. Size p2= new Size(widthmax,heightmax);
  273. //设置窗体的最小宽度和最小高度
  274. this.MinimumSize=p1;
  275. //设置窗体的最大宽度和最大高度
  276. this.MaximumSize=p2;
  277. }
  278. }
  279. }