SettingsForm.cs
上传用户:wangzj
上传日期:2016-05-05
资源大小:29k
文件大小:13k
源码类别:

Telnet客户端

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.IO;
  7. namespace TelnetClient
  8. {
  9. /// <summary>
  10. /// Form2 的摘要说明。
  11. /// </summary>
  12. public class SettingsForm : System.Windows.Forms.Form
  13. {
  14. public System.Windows.Forms.ToolTip ToolTip1;
  15. private System.Windows.Forms.ColorDialog colorDialog1;
  16. private System.Windows.Forms.FontDialog fontDialog1;
  17. private System.Windows.Forms.GroupBox groupBox1;
  18. private System.Windows.Forms.GroupBox groupBox2;
  19. private System.Windows.Forms.Button btnFont;
  20. private System.Windows.Forms.Label label2;
  21. private System.Windows.Forms.Label label3;
  22. private System.Windows.Forms.Button btnFGColor;
  23. private System.Windows.Forms.Button btnBGColor;
  24. private System.Windows.Forms.Label label1;
  25. private System.ComponentModel.IContainer components;
  26. public System.Windows.Forms.TextBox txtPort;
  27. public System.Windows.Forms.TextBox txtRemoteAddress;
  28. public System.Windows.Forms.Label _Label1_1;
  29. public System.Windows.Forms.Label Label1_0;
  30. public System.Windows.Forms.CheckBox chkAutoConnect;
  31. public System.Windows.Forms.Label lblEffect;
  32. public System.Windows.Forms.Button btnCancel;
  33. public System.Windows.Forms.Button btnOk;
  34. public SettingsForm()
  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 窗体设计器生成的代码
  59. /// <summary>
  60. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  61. /// 此方法的内容。
  62. /// </summary>
  63. private void InitializeComponent()
  64. {
  65. this.components = new System.ComponentModel.Container();
  66. this.btnCancel = new System.Windows.Forms.Button();
  67. this.btnOk = new System.Windows.Forms.Button();
  68. this.ToolTip1 = new System.Windows.Forms.ToolTip(this.components);
  69. this.colorDialog1 = new System.Windows.Forms.ColorDialog();
  70. this.fontDialog1 = new System.Windows.Forms.FontDialog();
  71. this.groupBox1 = new System.Windows.Forms.GroupBox();
  72. this.txtPort = new System.Windows.Forms.TextBox();
  73. this.txtRemoteAddress = new System.Windows.Forms.TextBox();
  74. this._Label1_1 = new System.Windows.Forms.Label();
  75. this.Label1_0 = new System.Windows.Forms.Label();
  76. this.chkAutoConnect = new System.Windows.Forms.CheckBox();
  77. this.groupBox2 = new System.Windows.Forms.GroupBox();
  78. this.btnFont = new System.Windows.Forms.Button();
  79. this.lblEffect = new System.Windows.Forms.Label();
  80. this.label2 = new System.Windows.Forms.Label();
  81. this.label3 = new System.Windows.Forms.Label();
  82. this.btnFGColor = new System.Windows.Forms.Button();
  83. this.btnBGColor = new System.Windows.Forms.Button();
  84. this.label1 = new System.Windows.Forms.Label();
  85. this.groupBox1.SuspendLayout();
  86. this.groupBox2.SuspendLayout();
  87. this.SuspendLayout();
  88. // 
  89. // btnCancel
  90. // 
  91. this.btnCancel.BackColor = System.Drawing.SystemColors.Control;
  92. this.btnCancel.Cursor = System.Windows.Forms.Cursors.Default;
  93. this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  94. this.btnCancel.ForeColor = System.Drawing.SystemColors.ControlText;
  95. this.btnCancel.Location = new System.Drawing.Point(432, 64);
  96. this.btnCancel.Name = "btnCancel";
  97. this.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  98. this.btnCancel.Size = new System.Drawing.Size(88, 25);
  99. this.btnCancel.TabIndex = 10;
  100. this.btnCancel.Text = "取消(&A)";
  101. // 
  102. // btnOk
  103. // 
  104. this.btnOk.BackColor = System.Drawing.SystemColors.Control;
  105. this.btnOk.Cursor = System.Windows.Forms.Cursors.Default;
  106. this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
  107. this.btnOk.ForeColor = System.Drawing.SystemColors.ControlText;
  108. this.btnOk.Location = new System.Drawing.Point(432, 24);
  109. this.btnOk.Name = "btnOk";
  110. this.btnOk.RightToLeft = System.Windows.Forms.RightToLeft.No;
  111. this.btnOk.Size = new System.Drawing.Size(88, 25);
  112. this.btnOk.TabIndex = 9;
  113. this.btnOk.Text = "确定(&O)";
  114. this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
  115. // 
  116. // groupBox1
  117. // 
  118. this.groupBox1.Controls.Add(this.txtPort);
  119. this.groupBox1.Controls.Add(this.txtRemoteAddress);
  120. this.groupBox1.Controls.Add(this._Label1_1);
  121. this.groupBox1.Controls.Add(this.Label1_0);
  122. this.groupBox1.Controls.Add(this.chkAutoConnect);
  123. this.groupBox1.Location = new System.Drawing.Point(16, 8);
  124. this.groupBox1.Name = "groupBox1";
  125. this.groupBox1.Size = new System.Drawing.Size(392, 136);
  126. this.groupBox1.TabIndex = 23;
  127. this.groupBox1.TabStop = false;
  128. this.groupBox1.Text = "连接参数设置";
  129. // 
  130. // txtPort
  131. // 
  132. this.txtPort.AcceptsReturn = true;
  133. this.txtPort.AutoSize = false;
  134. this.txtPort.BackColor = System.Drawing.SystemColors.Window;
  135. this.txtPort.Cursor = System.Windows.Forms.Cursors.IBeam;
  136. this.txtPort.ForeColor = System.Drawing.SystemColors.WindowText;
  137. this.txtPort.Location = new System.Drawing.Point(120, 64);
  138. this.txtPort.MaxLength = 0;
  139. this.txtPort.Name = "txtPort";
  140. this.txtPort.RightToLeft = System.Windows.Forms.RightToLeft.No;
  141. this.txtPort.Size = new System.Drawing.Size(153, 25);
  142. this.txtPort.TabIndex = 15;
  143. this.txtPort.Text = "23";
  144. // 
  145. // txtRemoteAddress
  146. // 
  147. this.txtRemoteAddress.AcceptsReturn = true;
  148. this.txtRemoteAddress.AutoSize = false;
  149. this.txtRemoteAddress.BackColor = System.Drawing.SystemColors.Window;
  150. this.txtRemoteAddress.Cursor = System.Windows.Forms.Cursors.IBeam;
  151. this.txtRemoteAddress.ForeColor = System.Drawing.SystemColors.WindowText;
  152. this.txtRemoteAddress.Location = new System.Drawing.Point(120, 24);
  153. this.txtRemoteAddress.MaxLength = 0;
  154. this.txtRemoteAddress.Name = "txtRemoteAddress";
  155. this.txtRemoteAddress.RightToLeft = System.Windows.Forms.RightToLeft.No;
  156. this.txtRemoteAddress.Size = new System.Drawing.Size(153, 25);
  157. this.txtRemoteAddress.TabIndex = 14;
  158. this.txtRemoteAddress.Text = "127.0.0.1";
  159. // 
  160. // _Label1_1
  161. // 
  162. this._Label1_1.BackColor = System.Drawing.SystemColors.Control;
  163. this._Label1_1.Cursor = System.Windows.Forms.Cursors.Default;
  164. this._Label1_1.ForeColor = System.Drawing.SystemColors.ControlText;
  165. this._Label1_1.Location = new System.Drawing.Point(8, 72);
  166. this._Label1_1.Name = "_Label1_1";
  167. this._Label1_1.RightToLeft = System.Windows.Forms.RightToLeft.No;
  168. this._Label1_1.Size = new System.Drawing.Size(137, 17);
  169. this._Label1_1.TabIndex = 17;
  170. this._Label1_1.Text = "Telnet服务器端口:";
  171. // 
  172. // Label1_0
  173. // 
  174. this.Label1_0.BackColor = System.Drawing.SystemColors.Control;
  175. this.Label1_0.Cursor = System.Windows.Forms.Cursors.Default;
  176. this.Label1_0.ForeColor = System.Drawing.SystemColors.ControlText;
  177. this.Label1_0.Location = new System.Drawing.Point(8, 32);
  178. this.Label1_0.Name = "Label1_0";
  179. this.Label1_0.RightToLeft = System.Windows.Forms.RightToLeft.No;
  180. this.Label1_0.Size = new System.Drawing.Size(137, 17);
  181. this.Label1_0.TabIndex = 16;
  182. this.Label1_0.Text = "Telnet服务器地址:";
  183. // 
  184. // chkAutoConnect
  185. // 
  186. this.chkAutoConnect.BackColor = System.Drawing.SystemColors.Control;
  187. this.chkAutoConnect.Cursor = System.Windows.Forms.Cursors.Default;
  188. this.chkAutoConnect.ForeColor = System.Drawing.SystemColors.ControlText;
  189. this.chkAutoConnect.Location = new System.Drawing.Point(16, 104);
  190. this.chkAutoConnect.Name = "chkAutoConnect";
  191. this.chkAutoConnect.RightToLeft = System.Windows.Forms.RightToLeft.No;
  192. this.chkAutoConnect.Size = new System.Drawing.Size(264, 17);
  193. this.chkAutoConnect.TabIndex = 18;
  194. this.chkAutoConnect.Text = "自动连接";
  195. // 
  196. // groupBox2
  197. // 
  198. this.groupBox2.Controls.Add(this.btnFont);
  199. this.groupBox2.Controls.Add(this.lblEffect);
  200. this.groupBox2.Controls.Add(this.label2);
  201. this.groupBox2.Controls.Add(this.label3);
  202. this.groupBox2.Controls.Add(this.btnFGColor);
  203. this.groupBox2.Controls.Add(this.btnBGColor);
  204. this.groupBox2.Controls.Add(this.label1);
  205. this.groupBox2.Location = new System.Drawing.Point(16, 168);
  206. this.groupBox2.Name = "groupBox2";
  207. this.groupBox2.Size = new System.Drawing.Size(392, 168);
  208. this.groupBox2.TabIndex = 24;
  209. this.groupBox2.TabStop = false;
  210. this.groupBox2.Text = "显示参数设置";
  211. // 
  212. // btnFont
  213. // 
  214. this.btnFont.Location = new System.Drawing.Point(232, 104);
  215. this.btnFont.Name = "btnFont";
  216. this.btnFont.Size = new System.Drawing.Size(136, 23);
  217. this.btnFont.TabIndex = 31;
  218. this.btnFont.Text = "设置显示字体(&F)";
  219. this.btnFont.Click += new System.EventHandler(this.btnFont_Click);
  220. // 
  221. // lblEffect
  222. // 
  223. this.lblEffect.BackColor = System.Drawing.Color.Black;
  224. this.lblEffect.ForeColor = System.Drawing.Color.Blue;
  225. this.lblEffect.Location = new System.Drawing.Point(112, 24);
  226. this.lblEffect.Name = "lblEffect";
  227. this.lblEffect.Size = new System.Drawing.Size(104, 120);
  228. this.lblEffect.TabIndex = 30;
  229. this.lblEffect.Text = "效果";
  230. this.lblEffect.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
  231. // 
  232. // label2
  233. // 
  234. this.label2.Location = new System.Drawing.Point(16, 104);
  235. this.label2.Name = "label2";
  236. this.label2.Size = new System.Drawing.Size(96, 16);
  237. this.label2.TabIndex = 29;
  238. this.label2.Text = "设置显示字体:";
  239. // 
  240. // label3
  241. // 
  242. this.label3.Location = new System.Drawing.Point(16, 72);
  243. this.label3.Name = "label3";
  244. this.label3.Size = new System.Drawing.Size(96, 16);
  245. this.label3.TabIndex = 27;
  246. this.label3.Text = "设置前景颜色:";
  247. // 
  248. // btnFGColor
  249. // 
  250. this.btnFGColor.Location = new System.Drawing.Point(232, 64);
  251. this.btnFGColor.Name = "btnFGColor";
  252. this.btnFGColor.Size = new System.Drawing.Size(136, 23);
  253. this.btnFGColor.TabIndex = 26;
  254. this.btnFGColor.Text = "设置前景颜色(&C)";
  255. this.btnFGColor.Click += new System.EventHandler(this.btnFGColor_Click);
  256. // 
  257. // btnBGColor
  258. // 
  259. this.btnBGColor.Location = new System.Drawing.Point(232, 24);
  260. this.btnBGColor.Name = "btnBGColor";
  261. this.btnBGColor.Size = new System.Drawing.Size(136, 23);
  262. this.btnBGColor.TabIndex = 25;
  263. this.btnBGColor.Text = "设置背景颜色(&B)";
  264. this.btnBGColor.Click += new System.EventHandler(this.btnBGColor_Click);
  265. // 
  266. // label1
  267. // 
  268. this.label1.Location = new System.Drawing.Point(16, 32);
  269. this.label1.Name = "label1";
  270. this.label1.Size = new System.Drawing.Size(96, 16);
  271. this.label1.TabIndex = 23;
  272. this.label1.Text = "设置背景颜色:";
  273. // 
  274. // SettingsForm
  275. // 
  276. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  277. this.ClientSize = new System.Drawing.Size(538, 351);
  278. this.Controls.Add(this.groupBox2);
  279. this.Controls.Add(this.groupBox1);
  280. this.Controls.Add(this.btnCancel);
  281. this.Controls.Add(this.btnOk);
  282. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  283. this.Name = "SettingsForm";
  284. this.Text = "设置Telnet客户端参数";
  285. this.groupBox1.ResumeLayout(false);
  286. this.groupBox2.ResumeLayout(false);
  287. this.ResumeLayout(false);
  288. }
  289. #endregion
  290. //保存程序参数设置
  291. private void saveSettings()
  292. {
  293. string path = System.Windows.Forms.Application.ExecutablePath
  294. + ".settings.set";
  295. if (File.Exists(path))  
  296. {
  297. File.Delete(path);
  298. }
  299. using (StreamWriter sw = File.AppendText(path)) 
  300. {
  301. sw.WriteLine(this.txtRemoteAddress.Text);
  302. sw.WriteLine(this.txtPort.Text);
  303. sw.WriteLine(this.chkAutoConnect.Checked);
  304. sw.WriteLine(this.lblEffect.BackColor.ToArgb());
  305. sw.WriteLine(this.lblEffect.ForeColor.ToArgb());
  306. sw.WriteLine(this.lblEffect.Font.FontFamily.Name);
  307. sw.WriteLine(this.lblEffect.Font.Size);
  308. sw.WriteLine(this.lblEffect.Font.Style);
  309. sw.WriteLine(this.lblEffect.Font.Unit);
  310. sw.WriteLine(this.lblEffect.Font.GdiCharSet);
  311. sw.WriteLine(this.lblEffect.Font.GdiVerticalFont);
  312. }
  313. }
  314. private void btnBGColor_Click(object sender, System.EventArgs e)
  315. {
  316. this.colorDialog1.Color = this.lblEffect.BackColor;
  317. if (this.colorDialog1.ShowDialog(this) == DialogResult.OK)
  318. {
  319. this.lblEffect.BackColor = this.colorDialog1.Color;
  320. }
  321. }
  322. private void btnFGColor_Click(object sender, System.EventArgs e)
  323. {
  324. this.colorDialog1.Color = this.lblEffect.ForeColor;
  325. if (this.colorDialog1.ShowDialog(this) == DialogResult.OK)
  326. {
  327. this.lblEffect.ForeColor = this.colorDialog1.Color;
  328. }
  329. }
  330. private void btnFont_Click(object sender, System.EventArgs e)
  331. {
  332. this.fontDialog1.Font = this.lblEffect.Font;
  333. if (this.fontDialog1.ShowDialog(this) == DialogResult.OK)
  334. {
  335. this.lblEffect.Font = this.fontDialog1.Font;
  336. }
  337. }
  338. private void btnOk_Click(object sender, System.EventArgs e)
  339. {
  340. saveSettings();
  341. }
  342. }
  343. }