From baba4fb95aea47d020f63cefa6ef622b10202598 Mon Sep 17 00:00:00 2001 From: zhangqi7131 Date: Thu, 1 Aug 2024 13:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=B0=E5=A2=9E=E6=9D=A1?= =?UTF-8?q?=E7=A0=81=E6=96=87=E6=9C=AC=E9=BB=98=E8=AE=A4=E5=80=BC=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- STS/Form2.Designer.cs | 9 ++++----- STS/Form2.cs | 26 ++++++++++---------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/STS/Form2.Designer.cs b/STS/Form2.Designer.cs index daeede2..f42213f 100644 --- a/STS/Form2.Designer.cs +++ b/STS/Form2.Designer.cs @@ -57,16 +57,15 @@ // // barcode_tb // - this.barcode_tb.ForeColor = System.Drawing.SystemColors.GrayText; + this.barcode_tb.ForeColor = System.Drawing.SystemColors.GrayText; this.barcode_tb.Location = new System.Drawing.Point(124, 46); this.barcode_tb.Name = "barcode_tb"; this.barcode_tb.Size = new System.Drawing.Size(234, 25); this.barcode_tb.TabIndex = 0; this.barcode_tb.Text = "T*****"; - this.barcode_tb.Click += new System.EventHandler(this.barcode_tb_Click); - this.barcode_tb.HideSelectionChanged += new System.EventHandler(this.barcode_tb_HideSelectionChanged); - this.barcode_tb.TextChanged += new System.EventHandler(this.barcode_tb_TextChanged); - this.barcode_tb.MouseLeave += new System.EventHandler(this.barcode_tb_MouseLeave); + this.barcode_tb.GotFocus += new System.EventHandler(this.barcode_tb_GotFocus); + this.barcode_tb.LostFocus += new System.EventHandler(this.barcode_tb_LostFocus); + // // STI_tb // diff --git a/STS/Form2.cs b/STS/Form2.cs index eadf81a..c73d560 100644 --- a/STS/Form2.cs +++ b/STS/Form2.cs @@ -93,30 +93,24 @@ namespace STS { Form2Closed?.Invoke(this, EventArgs.Empty); } - - private void barcode_tb_Click(object sender, EventArgs e) + //获得焦点 + private void barcode_tb_GotFocus(object sender, EventArgs e) { - //如果是首次点击才执行以下代码 + //点击时如果文本框里是默认值才执行以下代码 if (barcode_tb.Text.Equals("T*****")) { barcode_tb.Text = ""; barcode_tb.ForeColor = Color.Black; } } - - private void barcode_tb_TextChanged(object sender, EventArgs e) - { - - } - - private void barcode_tb_MouseLeave(object sender, EventArgs e) - { - - } - - private void barcode_tb_HideSelectionChanged(object sender, EventArgs e) + //失去焦点 + private void barcode_tb_LostFocus(object sender, EventArgs e) { - + if (barcode_tb.Text.Equals("")) + { + barcode_tb.Text = "T*****"; + barcode_tb.ForeColor = Color.Gray; + } } } }