From bcdc6869ccc92bc00a807a705e047211d702e282 Mon Sep 17 00:00:00 2001 From: phkim Date: Fri, 8 Jul 2022 13:24:14 +0900 Subject: [PATCH] improve interface --- RS232Test/Form1.Designer.cs | 8 ++++++-- RS232Test/Form1.cs | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/RS232Test/Form1.Designer.cs b/RS232Test/Form1.Designer.cs index bc18564..b35a3b5 100644 --- a/RS232Test/Form1.Designer.cs +++ b/RS232Test/Form1.Designer.cs @@ -71,13 +71,16 @@ // // printText // + this.printText.BackColor = System.Drawing.Color.White; this.printText.Dock = System.Windows.Forms.DockStyle.Fill; this.printText.Location = new System.Drawing.Point(3, 38); this.printText.Multiline = true; this.printText.Name = "printText"; + this.printText.ReadOnly = true; this.printText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.printText.Size = new System.Drawing.Size(394, 366); this.printText.TabIndex = 2; + this.printText.TabStop = false; // // commandText // @@ -85,7 +88,8 @@ this.commandText.Location = new System.Drawing.Point(3, 3); this.commandText.Name = "commandText"; this.commandText.Size = new System.Drawing.Size(288, 21); - this.commandText.TabIndex = 3; + this.commandText.TabIndex = 0; + this.commandText.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.commandText_KeyPress); // // Send // @@ -93,7 +97,7 @@ this.Send.Location = new System.Drawing.Point(297, 3); this.Send.Name = "Send"; this.Send.Size = new System.Drawing.Size(94, 23); - this.Send.TabIndex = 4; + this.Send.TabIndex = 1; this.Send.Text = "전송"; this.Send.UseVisualStyleBackColor = true; this.Send.Click += new System.EventHandler(this.Send_Click); diff --git a/RS232Test/Form1.cs b/RS232Test/Form1.cs index 3ec643e..be17292 100644 --- a/RS232Test/Form1.cs +++ b/RS232Test/Form1.cs @@ -211,6 +211,7 @@ TOC: {1} ppb private void Send_Click(object sender, EventArgs e) { string command = commandText.Text + "\r\n"; + if (!serialPort.IsOpen) { MessageBox.Show("포트가 열려있지 않습니다."); @@ -220,6 +221,8 @@ TOC: {1} ppb Print(string.Format("\t[CMD] {0} {1}", DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"), commandText.Text)); serialPort.Write(command); + + commandText.Clear(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) @@ -228,6 +231,14 @@ TOC: {1} ppb serialPort.Close(); } + private void commandText_KeyPress(object sender, KeyPressEventArgs e) + { + if (e.KeyChar != (char)Keys.Enter) + return; + + Send_Click(sender, e); + } + } }