SerialLoginDialog.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:25k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: SerialLoginDialog.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.IO;
  7. using System.Text;
  8. using System.Drawing;
  9. using System.Collections;
  10. using System.Collections.Specialized;
  11. using System.ComponentModel;
  12. using System.Windows.Forms;
  13. using Poderosa.Toolkit;
  14. using EnumDescAttributeT = Poderosa.Toolkit.EnumDescAttribute;
  15. using Poderosa.Connection;
  16. using Poderosa.ConnectionParam;
  17. using Poderosa.Communication;
  18. using Poderosa.Terminal;
  19. namespace Poderosa.Forms {
  20. /// <summary>
  21. /// SerialLoginDialog 偺奣梫偺愢柧偱偡丅
  22. /// </summary>
  23. internal class SerialLoginDialog : System.Windows.Forms.Form {
  24. private ConnectionTag _result;
  25. private System.Windows.Forms.Button _loginButton;
  26. private System.Windows.Forms.Button _cancelButton;
  27. private System.Windows.Forms.GroupBox _terminalGroup;
  28. private ComboBox _logTypeBox;
  29. private System.Windows.Forms.Label _logTypeLabel;
  30. private ComboBox _newLineBox;
  31. private ComboBox _localEchoBox;
  32. private System.Windows.Forms.Label _localEchoLabel;
  33. private System.Windows.Forms.Label _newLineLabel;
  34. private ComboBox _logFileBox;
  35. private System.Windows.Forms.Label _logFileLabel;
  36. private ComboBox _encodingBox;
  37. private System.Windows.Forms.Label _encodingLabel;
  38. private Button _selectLogButton;
  39. private System.Windows.Forms.GroupBox _serialGroup;
  40. private ComboBox _flowControlBox;
  41. private System.Windows.Forms.Label _flowControlLabel;
  42. private ComboBox _stopBitsBox;
  43. private System.Windows.Forms.Label _stopBitsLabel;
  44. private ComboBox _parityBox;
  45. private System.Windows.Forms.Label _parityLabel;
  46. private ComboBox _dataBitsBox;
  47. private System.Windows.Forms.Label _dataBitsLabel;
  48. private ComboBox _baudRateBox;
  49. private System.Windows.Forms.Label _baudRateLabel;
  50. private ComboBox _portBox;
  51. private System.Windows.Forms.Label _portLabel;
  52. private Label _transmitDelayPerCharLabel;
  53. private TextBox _transmitDelayPerCharBox;
  54. private Label _transmitDelayPerLineLabel;
  55. private TextBox _transmitDelayPerLineBox;
  56. /// <summary>
  57. /// 昁梫側僨僓僀僫曄悢偱偡丅
  58. /// </summary>
  59. private System.ComponentModel.Container components = null;
  60. public SerialLoginDialog() {
  61. //
  62. // Windows 僼僅乕儉 僨僓僀僫 僒億乕僩偵昁梫偱偡丅
  63. //
  64. InitializeComponent();
  65. this._serialGroup.Text = GApp.Strings.GetString("Form.SerialLoginDialog._serialGroup");
  66. //埲壓丄SerialConfig偲僥僉僗僩傪嫟梡
  67. this._portLabel.Text = GApp.Strings.GetString("Form.SerialConfig._portLabel");
  68. this._baudRateLabel.Text = GApp.Strings.GetString("Form.SerialConfig._baudRateLabel");
  69. this._dataBitsLabel.Text = GApp.Strings.GetString("Form.SerialConfig._dataBitsLabel");
  70. this._parityLabel.Text = GApp.Strings.GetString("Form.SerialConfig._parityLabel");
  71. this._stopBitsLabel.Text = GApp.Strings.GetString("Form.SerialConfig._stopBitsLabel");
  72. this._flowControlLabel.Text = GApp.Strings.GetString("Form.SerialConfig._flowControlLabel");
  73. this._transmitDelayPerLineLabel.Text = "Transmit Delay(msec/line)";
  74. this._transmitDelayPerCharLabel.Text = "Transmit Delay(msec/char)";
  75. string bits = GApp.Strings.GetString("Caption.SerialConfig.Bits");
  76. this._dataBitsBox.Items.AddRange(new object[] {
  77.   String.Format("{0}{1}", 7, bits),
  78.   String.Format("{0}{1}", 8, bits)});
  79. this._terminalGroup.Text = GApp.Strings.GetString("Form.SerialLoginDialog._terminalGroup");
  80. //埲壓丄LoginDialog偲僥僉僗僩嫟梡
  81. this._localEchoLabel.Text = GApp.Strings.GetString("Form.LoginDialog._localEchoLabel");
  82. this._newLineLabel.Text = GApp.Strings.GetString("Form.LoginDialog._newLineLabel");
  83. this._logFileLabel.Text = GApp.Strings.GetString("Form.LoginDialog._logFileLabel");
  84. this._encodingLabel.Text = GApp.Strings.GetString("Form.LoginDialog._encodingLabel");
  85. this._logTypeLabel.Text = GApp.Strings.GetString("Form.LoginDialog._logTypeLabel");
  86. this._localEchoBox.Items.AddRange(new object[] {
  87.    GApp.Strings.GetString("Common.DoNot"),
  88.    GApp.Strings.GetString("Common.Do")});
  89. this._loginButton.Text = GApp.Strings.GetString("Common.OK");
  90. this._cancelButton.Text = GApp.Strings.GetString("Common.Cancel");
  91. this.Text = GApp.Strings.GetString("Form.SerialLoginDialog.Text");
  92. //
  93. // TODO: InitializeComponent 屇傃弌偟偺屻偵丄僐儞僗僩儔僋僞 僐乕僪傪捛壛偟偰偔偩偝偄丅
  94. //
  95. InitUI();
  96. }
  97. /// <summary>
  98. /// 巊梡偝傟偰偄傞儕僜乕僗偵屻張棟傪幚峴偟傑偡丅
  99. /// </summary>
  100. protected override void Dispose( bool disposing ) {
  101. if( disposing ) {
  102. if(components != null) {
  103. components.Dispose();
  104. }
  105. }
  106. base.Dispose( disposing );
  107. }
  108. #region Windows Form Designer generated code
  109. /// <summary>
  110. /// 僨僓僀僫 僒億乕僩偵昁梫側儊僜僢僪偱偡丅偙偺儊僜僢僪偺撪梕傪
  111. /// 僐乕僪 僄僨傿僞偱曄峏偟側偄偱偔偩偝偄丅
  112. /// this._logTypeBox.Items.AddRange(EnumDescAttributeT.For(typeof(LogType)).DescriptionCollection());
  113. /// this._newLineBox.Items.AddRange(EnumDescAttributeT.For(typeof(NewLine)).DescriptionCollection());
  114. /// this._encodingBox.Items.AddRange(GUtil.EncodingDescription(GApp.Options.Encodings));
  115. /// this._stopBitsBox.Items.AddRange(EnumDescAttributeT.For(typeof(StopBits)).DescriptionCollection());
  116. /// this._parityBox.Items.AddRange(EnumDescAttributeT.For(typeof(Parity)).DescriptionCollection());
  117. ///this._flowControlBox.Items.AddRange(EnumDescAttributeTs.For(typeof(FlowControl)).DescriptionCollection());
  118. ///this._baudRateBox.Items.AddRange(TerminalUtil.BaudRates);
  119. /// </summary>
  120. private void InitializeComponent() {
  121. this._serialGroup = new System.Windows.Forms.GroupBox();
  122. this._portLabel = new System.Windows.Forms.Label();
  123. this._portBox = new ComboBox();
  124. this._baudRateLabel = new System.Windows.Forms.Label();
  125. this._baudRateBox = new ComboBox();
  126. this._dataBitsLabel = new System.Windows.Forms.Label();
  127. this._dataBitsBox = new ComboBox();
  128. this._parityLabel = new System.Windows.Forms.Label();
  129. this._parityBox = new ComboBox();
  130. this._stopBitsLabel = new System.Windows.Forms.Label();
  131. this._stopBitsBox = new ComboBox();
  132. this._flowControlLabel = new System.Windows.Forms.Label();
  133. this._flowControlBox = new ComboBox();
  134. this._transmitDelayPerCharLabel = new Label();
  135. this._transmitDelayPerCharBox = new TextBox();
  136. this._transmitDelayPerLineLabel = new Label();
  137. this._transmitDelayPerLineBox = new TextBox();
  138. this._terminalGroup = new System.Windows.Forms.GroupBox();
  139. this._logTypeBox = new ComboBox();
  140. this._logTypeLabel = new System.Windows.Forms.Label();
  141. this._newLineBox = new ComboBox();
  142. this._localEchoBox = new ComboBox();
  143. this._localEchoLabel = new System.Windows.Forms.Label();
  144. this._newLineLabel = new System.Windows.Forms.Label();
  145. this._logFileBox = new ComboBox();
  146. this._logFileLabel = new System.Windows.Forms.Label();
  147. this._encodingBox = new ComboBox();
  148. this._encodingLabel = new System.Windows.Forms.Label();
  149. this._selectLogButton = new Button();
  150. this._terminalGroup.SuspendLayout();
  151. this._serialGroup.SuspendLayout();
  152. this._loginButton = new System.Windows.Forms.Button();
  153. this._cancelButton = new System.Windows.Forms.Button();
  154. this.SuspendLayout();
  155. // 
  156. // _serialGroup
  157. // 
  158. this._serialGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  159.    this._transmitDelayPerCharBox,
  160.    this._transmitDelayPerCharLabel,
  161.    this._transmitDelayPerLineBox,
  162.    this._transmitDelayPerLineLabel,
  163.    this._flowControlBox,
  164.    this._flowControlLabel,
  165.    this._stopBitsBox,
  166.    this._stopBitsLabel,
  167.    this._parityBox,
  168.    this._parityLabel,
  169.    this._dataBitsBox,
  170.    this._dataBitsLabel,
  171.    this._baudRateBox,
  172.    this._baudRateLabel,
  173.    this._portBox,
  174.    this._portLabel});
  175. this._serialGroup.Location = new System.Drawing.Point(8, 8);
  176. this._serialGroup.Name = "_serialGroup";
  177. this._serialGroup.FlatStyle = FlatStyle.System;
  178. this._serialGroup.Size = new System.Drawing.Size(296, 224);
  179. this._serialGroup.TabIndex = 0;
  180. this._serialGroup.TabStop = false;
  181. // 
  182. // _portLabel
  183. // 
  184. this._portLabel.Location = new System.Drawing.Point(8, 16);
  185. this._portLabel.Name = "_portLabel";
  186. this._portLabel.Size = new System.Drawing.Size(88, 23);
  187. this._portLabel.TabIndex = 1;
  188. this._portLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  189. // 
  190. // _portBox
  191. // 
  192. this._portBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  193. this._portBox.Location = new System.Drawing.Point(112, 16);
  194. this._portBox.Name = "_portBox";
  195. this._portBox.Size = new System.Drawing.Size(120, 20);
  196. this._portBox.TabIndex = 2;
  197. // 
  198. // _baudRateLabel
  199. // 
  200. this._baudRateLabel.Location = new System.Drawing.Point(8, 40);
  201. this._baudRateLabel.Name = "_baudRateLabel";
  202. this._baudRateLabel.Size = new System.Drawing.Size(88, 23);
  203. this._baudRateLabel.TabIndex = 3;
  204. this._baudRateLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  205. // 
  206. // _baudRateBox
  207. // 
  208. this._baudRateBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  209. this._baudRateBox.Items.AddRange(TerminalUtil.BaudRates);
  210. this._baudRateBox.Location = new System.Drawing.Point(112, 40);
  211. this._baudRateBox.Name = "_baudRateBox";
  212. this._baudRateBox.Size = new System.Drawing.Size(120, 20);
  213. this._baudRateBox.TabIndex = 4;
  214. // 
  215. // _dataBitsLabel
  216. // 
  217. this._dataBitsLabel.Location = new System.Drawing.Point(8, 64);
  218. this._dataBitsLabel.Name = "_dataBitsLabel";
  219. this._dataBitsLabel.Size = new System.Drawing.Size(88, 23);
  220. this._dataBitsLabel.TabIndex = 5;
  221. this._dataBitsLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  222. // 
  223. // _dataBitsBox
  224. // 
  225. this._dataBitsBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  226. this._dataBitsBox.Location = new System.Drawing.Point(112, 64);
  227. this._dataBitsBox.Name = "_dataBitsBox";
  228. this._dataBitsBox.Size = new System.Drawing.Size(120, 20);
  229. this._dataBitsBox.TabIndex = 6;
  230. // 
  231. // _parityLabel
  232. // 
  233. this._parityLabel.Location = new System.Drawing.Point(8, 88);
  234. this._parityLabel.Name = "_parityLabel";
  235. this._parityLabel.Size = new System.Drawing.Size(88, 23);
  236. this._parityLabel.TabIndex = 7;
  237. this._parityLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  238. // 
  239. // _parityBox
  240. // 
  241. this._parityBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  242. this._parityBox.Items.AddRange(EnumDescAttributeT.For(typeof(Parity)).DescriptionCollection());
  243. this._parityBox.Location = new System.Drawing.Point(112, 88);
  244. this._parityBox.Name = "_parityBox";
  245. this._parityBox.Size = new System.Drawing.Size(120, 20);
  246. this._parityBox.TabIndex = 8;
  247. // 
  248. // _stopBitsLabel
  249. // 
  250. this._stopBitsLabel.Location = new System.Drawing.Point(8, 112);
  251. this._stopBitsLabel.Name = "_stopBitsLabel";
  252. this._stopBitsLabel.Size = new System.Drawing.Size(88, 23);
  253. this._stopBitsLabel.TabIndex = 9;
  254. this._stopBitsLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  255. // 
  256. // _stopBitsBox
  257. // 
  258. this._stopBitsBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  259. this._stopBitsBox.Items.AddRange(EnumDescAttributeT.For(typeof(StopBits)).DescriptionCollection());
  260. this._stopBitsBox.Location = new System.Drawing.Point(112, 112);
  261. this._stopBitsBox.Name = "_stopBitsBox";
  262. this._stopBitsBox.Size = new System.Drawing.Size(120, 20);
  263. this._stopBitsBox.TabIndex = 10;
  264. // 
  265. // _flowControlLabel
  266. // 
  267. this._flowControlLabel.Location = new System.Drawing.Point(8, 136);
  268. this._flowControlLabel.Name = "_flowControlLabel";
  269. this._flowControlLabel.Size = new System.Drawing.Size(88, 23);
  270. this._flowControlLabel.TabIndex = 11;
  271. this._flowControlLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  272. // 
  273. // _flowControlBox
  274. // 
  275. this._flowControlBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  276. this._flowControlBox.Location = new System.Drawing.Point(112, 136);
  277. this._flowControlBox.Name = "_flowControlBox";
  278. this._flowControlBox.Size = new System.Drawing.Size(120, 20);
  279. this._flowControlBox.Items.AddRange(EnumDescAttributeT.For(typeof(FlowControl)).DescriptionCollection());
  280. this._flowControlBox.TabIndex = 12;
  281. // 
  282. // _transmitDelayPerCharLabel
  283. // 
  284. this._transmitDelayPerCharLabel.Location = new System.Drawing.Point(8, 160);
  285. this._transmitDelayPerCharLabel.Name = "_transmitDelayPerCharLabel";
  286. this._transmitDelayPerCharLabel.Size = new System.Drawing.Size(88, 23);
  287. this._transmitDelayPerCharLabel.TabIndex = 13;
  288. this._transmitDelayPerCharLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  289. // 
  290. // _transmitDelayPerCharBox
  291. // 
  292. this._transmitDelayPerCharBox.Location = new System.Drawing.Point(112, 160);
  293. this._transmitDelayPerCharBox.Name = "_transmitDelayPerCharBox";
  294. this._transmitDelayPerCharBox.Size = new System.Drawing.Size(120, 20);
  295. this._transmitDelayPerCharBox.TabIndex = 14;
  296. this._transmitDelayPerCharBox.MaxLength = 3;
  297. // 
  298. // _transmitDelayPerLineLabel
  299. // 
  300. this._transmitDelayPerLineLabel.Location = new System.Drawing.Point(8, 184);
  301. this._transmitDelayPerLineLabel.Name = "_transmitDelayPerLineLabel";
  302. this._transmitDelayPerLineLabel.Size = new System.Drawing.Size(88, 23);
  303. this._transmitDelayPerLineLabel.TabIndex = 15;
  304. this._transmitDelayPerLineLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  305. // 
  306. // _transmitDelayPerLineBox
  307. // 
  308. this._transmitDelayPerLineBox.Location = new System.Drawing.Point(112, 184);
  309. this._transmitDelayPerLineBox.Name = "_transmitDelayPerLineBox";
  310. this._transmitDelayPerLineBox.Size = new System.Drawing.Size(120, 20);
  311. this._transmitDelayPerLineBox.TabIndex = 16;
  312. this._transmitDelayPerLineBox.MaxLength = 3;
  313. // 
  314. // _terminalGroup
  315. // 
  316. this._terminalGroup.Controls.AddRange(new System.Windows.Forms.Control[] {
  317.  this._logTypeBox,
  318.  this._logTypeLabel,
  319.  this._newLineBox,
  320.  this._localEchoBox,
  321.  this._localEchoLabel,
  322.  this._newLineLabel,
  323.  this._logFileBox,
  324.  this._logFileLabel,
  325.  this._encodingBox,
  326.  this._encodingLabel,
  327.  this._selectLogButton});
  328. this._terminalGroup.Location = new System.Drawing.Point(8, 240);
  329. this._terminalGroup.Name = "_terminalGroup";
  330. this._terminalGroup.FlatStyle = FlatStyle.System;
  331. this._terminalGroup.Size = new System.Drawing.Size(296, 144);
  332. this._terminalGroup.TabIndex = 17;
  333. this._terminalGroup.TabStop = false;
  334. // 
  335. // _logTypeLabel
  336. // 
  337. this._logTypeLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  338. this._logTypeLabel.Location = new System.Drawing.Point(8, 16);
  339. this._logTypeLabel.Name = "_logTypeLabel";
  340. this._logTypeLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  341. this._logTypeLabel.Size = new System.Drawing.Size(120, 16);
  342. this._logTypeLabel.TabIndex = 18;
  343. this._logTypeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  344. // 
  345. // _logTypeBox
  346. // 
  347. this._logTypeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  348. this._logTypeBox.Items.AddRange(EnumDescAttributeT.For(typeof(LogType)).DescriptionCollection());
  349. this._logTypeBox.Location = new System.Drawing.Point(112, 16);
  350. this._logTypeBox.Name = "_logTypeBox";
  351. this._logTypeBox.Size = new System.Drawing.Size(120, 20);
  352. this._logTypeBox.TabIndex = 19;
  353. this._logTypeBox.SelectedIndexChanged += new System.EventHandler(this.OnLogTypeChanged);
  354. // 
  355. // _logFileLabel
  356. // 
  357. this._logFileLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  358. this._logFileLabel.Location = new System.Drawing.Point(8, 40);
  359. this._logFileLabel.Name = "_logFileLabel";
  360. this._logFileLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  361. this._logFileLabel.Size = new System.Drawing.Size(88, 16);
  362. this._logFileLabel.TabIndex = 20;
  363. this._logFileLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  364. // 
  365. // _logFileBox
  366. // 
  367. this._logFileBox.Location = new System.Drawing.Point(112, 40);
  368. this._logFileBox.Name = "_logFileBox";
  369. this._logFileBox.Size = new System.Drawing.Size(144, 20);
  370. this._logFileBox.TabIndex = 21;
  371. // 
  372. // _selectLogButton
  373. // 
  374. this._selectLogButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
  375. this._selectLogButton.ImageIndex = 0;
  376. this._selectLogButton.FlatStyle = FlatStyle.System;
  377. this._selectLogButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  378. this._selectLogButton.Location = new System.Drawing.Point(256, 40);
  379. this._selectLogButton.Name = "_selectLogButton";
  380. this._selectLogButton.RightToLeft = System.Windows.Forms.RightToLeft.No;
  381. this._selectLogButton.Size = new System.Drawing.Size(19, 19);
  382. this._selectLogButton.TabIndex = 22;
  383. this._selectLogButton.Text = "...";
  384. this._selectLogButton.Click += new System.EventHandler(this.SelectLog);
  385. // 
  386. // _encodingLabel
  387. // 
  388. this._encodingLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  389. this._encodingLabel.Location = new System.Drawing.Point(8, 64);
  390. this._encodingLabel.Name = "_encodingLabel";
  391. this._encodingLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  392. this._encodingLabel.Size = new System.Drawing.Size(96, 16);
  393. this._encodingLabel.TabIndex = 23;
  394. this._encodingLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  395. // 
  396. // _encodingBox
  397. // 
  398. this._encodingBox.Items.AddRange(EnumDescAttributeT.For(typeof(EncodingType)).DescriptionCollection());
  399. this._encodingBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  400. this._encodingBox.Location = new System.Drawing.Point(112, 64);
  401. this._encodingBox.Name = "_encodingBox";
  402. this._encodingBox.Size = new System.Drawing.Size(120, 20);
  403. this._encodingBox.TabIndex = 24;
  404. // 
  405. // _localEchoLabel
  406. // 
  407. this._localEchoLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  408. this._localEchoLabel.Location = new System.Drawing.Point(8, 88);
  409. this._localEchoLabel.Name = "_localEchoLabel";
  410. this._localEchoLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  411. this._localEchoLabel.Size = new System.Drawing.Size(96, 16);
  412. this._localEchoLabel.TabIndex = 25;
  413. this._localEchoLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  414. // 
  415. // _localEchoBox
  416. // 
  417. this._localEchoBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  418. this._localEchoBox.Location = new System.Drawing.Point(112, 88);
  419. this._localEchoBox.Name = "_localEchoBox";
  420. this._localEchoBox.Size = new System.Drawing.Size(120, 20);
  421. this._localEchoBox.TabIndex = 26;
  422. // 
  423. // _newLineLabel
  424. // 
  425. this._newLineLabel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
  426. this._newLineLabel.Location = new System.Drawing.Point(8, 112);
  427. this._newLineLabel.Name = "_newLineLabel";
  428. this._newLineLabel.RightToLeft = System.Windows.Forms.RightToLeft.No;
  429. this._newLineLabel.Size = new System.Drawing.Size(96, 16);
  430. this._newLineLabel.TabIndex = 27;
  431. this._newLineLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  432. // 
  433. // _newLineBox
  434. // 
  435. this._newLineBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  436. this._newLineBox.Items.AddRange(EnumDescAttributeT.For(typeof(NewLine)).DescriptionCollection());
  437. this._newLineBox.Location = new System.Drawing.Point(112, 112);
  438. this._newLineBox.Name = "_newLineBox";
  439. this._newLineBox.Size = new System.Drawing.Size(120, 20);
  440. this._newLineBox.TabIndex = 28;
  441. // 
  442. // _loginButton
  443. // 
  444. this._loginButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  445. this._loginButton.Location = new System.Drawing.Point(136, 392);
  446. this._loginButton.Name = "_loginButton";
  447. this._loginButton.FlatStyle = FlatStyle.System;
  448. this._loginButton.TabIndex = 29;
  449. this._loginButton.Click += new System.EventHandler(this.OnOK);
  450. // 
  451. // _cancelButton
  452. // 
  453. this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  454. this._cancelButton.Location = new System.Drawing.Point(224, 392);
  455. this._cancelButton.Name = "_cancelButton";
  456. this._cancelButton.FlatStyle = FlatStyle.System;
  457. this._cancelButton.TabIndex = 30;
  458. // 
  459. // SerialLoginDialog
  460. // 
  461. this.AcceptButton = this._loginButton;
  462. this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
  463. this.CancelButton = this._cancelButton;
  464. this.ClientSize = new System.Drawing.Size(314, 423);
  465. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  466.   this._serialGroup,
  467.   this._terminalGroup,
  468.   this._cancelButton,
  469.   this._loginButton});
  470. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  471. this.MaximizeBox = false;
  472. this.MinimizeBox = false;
  473. this.Name = "SerialLoginDialog";
  474. this.ShowInTaskbar = false;
  475. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  476. this._terminalGroup.ResumeLayout(false);
  477. this._serialGroup.ResumeLayout(false);
  478. this.ResumeLayout(false);
  479. }
  480. #endregion
  481. public ConnectionTag Result {
  482. get {
  483. return _result;
  484. }
  485. }
  486. private void InitUI() {
  487. for(int i=1; i<=GApp.Options.SerialCount; i++)
  488. _portBox.Items.Add(String.Format("COM{0}", i));
  489. StringCollection c = GApp.ConnectionHistory.LogPaths;
  490. foreach(string p in c) _logFileBox.Items.Add(p);
  491. if(GApp.Options.DefaultLogType!=LogType.None) {
  492. _logTypeBox.SelectedIndex = (int)GApp.Options.DefaultLogType;
  493. string t = GUtil.CreateLogFileName(null);
  494. _logFileBox.Items.Add(t);
  495. _logFileBox.Text = t;
  496. }
  497. else
  498. _logTypeBox.SelectedIndex = 0;
  499. AdjustUI();
  500. }
  501. private void AdjustUI() {
  502. bool e = _logTypeBox.SelectedIndex!=(int)LogType.None;
  503. _logFileBox.Enabled = e;
  504. _selectLogButton.Enabled = e;
  505. }
  506. public void ApplyParam(SerialTerminalParam param) {
  507. _portBox.SelectedIndex = param.Port-1;
  508. //偙傟傜偺SelectedIndex偺愝掕偼僐儞儃儃僢僋僗偵愝掕偟偨崁栚弴偵埶懚偟偰偄傞偺偱拲堄怺偔偡傞偙偲
  509. _baudRateBox.SelectedIndex = _baudRateBox.FindStringExact(param.BaudRate.ToString());
  510. _dataBitsBox.SelectedIndex = param.ByteSize==7? 0 : 1;
  511. _parityBox.SelectedIndex = (int)param.Parity;
  512. _stopBitsBox.SelectedIndex = (int)param.StopBits;
  513. _flowControlBox.SelectedIndex = (int)param.FlowControl;
  514. _encodingBox.SelectedIndex = (int)param.EncodingProfile.Type;
  515. _newLineBox.SelectedIndex = _newLineBox.FindStringExact(param.TransmitNL.ToString());
  516. _localEchoBox.SelectedIndex = param.LocalEcho? 1 : 0;
  517. _transmitDelayPerCharBox.Text = param.TransmitDelayPerChar.ToString();
  518. _transmitDelayPerLineBox.Text = param.TransmitDelayPerLine.ToString();
  519. }
  520. private void OnOK(object sender, EventArgs args) {
  521. _result = null;
  522. this.DialogResult = DialogResult.None;
  523. SerialTerminalParam param = ValidateParam();
  524. if(param==null) return;
  525. try {
  526. _result = CommunicationUtil.CreateNewSerialConnection(this, param);
  527. if(_result!=null)
  528. this.DialogResult = DialogResult.OK;
  529. }
  530. catch(Exception ex) {
  531. GUtil.Warning(this, ex.Message);
  532. }
  533. }
  534. private SerialTerminalParam ValidateParam() {
  535. SerialTerminalParam p = new SerialTerminalParam();
  536. try {
  537. p.LogType = (LogType)EnumDescAttributeT.For(typeof(LogType)).FromDescription(_logTypeBox.Text, LogType.None);
  538. if(p.LogType!=LogType.None) {
  539. p.LogPath = _logFileBox.Text;
  540. if(p.LogPath==GUtil.CreateLogFileName(null)) p.LogPath = GUtil.CreateLogFileName(String.Format("com{0}", _portBox.SelectedIndex+1));
  541. LogFileCheckResult r = GCUtil.CheckLogFileName(p.LogPath, this);
  542. if(r==LogFileCheckResult.Cancel || r==LogFileCheckResult.Error) return null;
  543. p.LogAppend = (r==LogFileCheckResult.Append);
  544. }
  545. p.Port = _portBox.SelectedIndex+1;
  546. p.BaudRate = Int32.Parse(_baudRateBox.Text);
  547. p.ByteSize = (byte)(_dataBitsBox.SelectedIndex==0? 7 : 8);
  548. p.StopBits = (StopBits)_stopBitsBox.SelectedIndex;
  549. p.Parity = (Parity)_parityBox.SelectedIndex;
  550. p.FlowControl = (FlowControl)_flowControlBox.SelectedIndex;
  551. p.EncodingProfile = EncodingProfile.Get((EncodingType)_encodingBox.SelectedIndex);
  552. p.LocalEcho = _localEchoBox.SelectedIndex==1;
  553. p.TransmitNL = (NewLine)EnumDescAttributeT.For(typeof(NewLine)).FromDescription(_newLineBox.Text, LogType.None);
  554. p.TransmitDelayPerChar = Int32.Parse(_transmitDelayPerCharBox.Text);
  555. p.TransmitDelayPerLine = Int32.Parse(_transmitDelayPerLineBox.Text);
  556. return p;
  557. }
  558. catch(Exception ex) {
  559. GUtil.Warning(this, ex.Message);
  560. return null;
  561. }
  562. }
  563. private void SelectLog(object sender, System.EventArgs e) {
  564. string fn = GCUtil.SelectLogFileByDialog(this);
  565. if(fn!=null) _logFileBox.Text = fn;
  566. }
  567. private void OnLogTypeChanged(object sender, System.EventArgs args) {
  568. AdjustUI();
  569. }
  570. }
  571. }