Browse Source

添加PlaceHolder控件

章政 8 years ago
parent
commit
f269c2c63a

+ 26 - 3
UAS-MES/CustomControl/TextBoxWithIcon/TextBoxWithPlaceHolder.Designer.cs

@@ -28,16 +28,39 @@
         /// </summary>
         private void InitializeComponent()
         {
+            this.TextBox = new UAS_MES.CustomControl.TextBoxWithIcon.EnterTextBox();
             this.SuspendLayout();
             // 
+            // TextBox
+            // 
+            this.TextBox.AllPower = null;
+            this.TextBox.BackColor = System.Drawing.Color.White;
+            this.TextBox.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.TextBox.ID = null;
+            this.TextBox.Location = new System.Drawing.Point(0, 0);
+            this.TextBox.Name = "TextBox";
+            this.TextBox.Power = null;
+            this.TextBox.Size = new System.Drawing.Size(241, 25);
+            this.TextBox.Str = null;
+            this.TextBox.Str1 = null;
+            this.TextBox.Str2 = null;
+            this.TextBox.TabIndex = 0;
+            this.TextBox.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
+            this.TextBox.Enter += new System.EventHandler(this.TextBox_Enter);
+            this.TextBox.Leave += new System.EventHandler(this.TextBox_Leave);
+            // 
             // TextBoxWithPlaceHolder
             // 
-            this.Size = new System.Drawing.Size(241, 21);
-            this.Enter += new System.EventHandler(this.TextBoxWithPlaceHolder_Enter);
-            this.Leave += new System.EventHandler(this.TextBoxWithPlaceHolder_Leave);
+            this.BackColor = System.Drawing.Color.Transparent;
+            this.Controls.Add(this.TextBox);
+            this.Name = "TextBoxWithPlaceHolder";
+            this.Size = new System.Drawing.Size(241, 28);
             this.ResumeLayout(false);
+            this.PerformLayout();
 
         }
         #endregion
+
+        private EnterTextBox TextBox;
     }
 }

+ 42 - 23
UAS-MES/CustomControl/TextBoxWithIcon/TextBoxWithPlaceHolder.cs

@@ -1,9 +1,10 @@
-using System.Drawing;
+using System;
+using System.Drawing;
 using System.Windows.Forms;
 
 namespace UAS_MES.CustomControl.TextBoxWithIcon
 {
-    public partial class TextBoxWithPlaceHolder : EnterTextBox
+    public partial class TextBoxWithPlaceHolder : UserControl
     {
         //记录一个PlaceHolder,第一次对这个文本框赋的值
         string PlaceHolder1;
@@ -21,45 +22,63 @@ namespace UAS_MES.CustomControl.TextBoxWithIcon
             }
         }
 
+        public override string Text
+        {
+            get
+            {
+                if (TextBox.Text == PlaceHolder1)
+                {
+                    return "";
+                }
+                return TextBox.Text;
+            }
+
+            set
+            {
+                TextBox.Text = value;
+            }
+        }
+
+        public delegate void OnTextChange(object sender, EventArgs e);
+
+        public event OnTextChange UserControlTextChanged;
+
         public TextBoxWithPlaceHolder()
         {
             InitializeComponent();
-            this.GotFocus += TextBoxWithPlaceHolder_GetFocus;
+            Load += TextBoxWithPlaceHolder_Load;
         }
 
-        private void TextBoxWithPlaceHolder_GetFocus(object sender, System.EventArgs e) {
-
+        private void TextBoxWithPlaceHolder_Load(object sender, System.EventArgs e)
+        {
+            TextBox.Text = PlaceHolder1;
+            TextBox.ForeColor = Color.Silver;
         }
 
-        private void TextBoxWithPlaceHolder_Leave(object sender, System.EventArgs e)
+        private void TextBox_Leave(object sender, System.EventArgs e)
         {
             //失去焦点的时候如果文本框存在内容就把文字变色
-            BackColor = Color.White;
-            if (Text == "")
+            TextBox.BackColor = Color.White;
+            if (TextBox.Text == "")
             {
-                ForeColor = Color.Silver;
-                Text = PlaceHolder1;
+                TextBox.ForeColor = Color.Silver;
+                TextBox.Text = PlaceHolder1;
             }
         }
 
-        private void TextBoxWithPlaceHolder_Enter(object sender, System.EventArgs e)
+        private void TextBox_Enter(object sender, System.EventArgs e)
         {
-            BackColor = Color.GreenYellow;
-            ForeColor = Color.Black;
-            //如果文本框的内容等与PlaceHolder就将文本框清空
-            if (Text == PlaceHolder1)
+            TextBox.ForeColor = Color.Black;
+            if (TextBox.Text == PlaceHolder1)
             {
-                Clear();
+                TextBox.Text = "";
             }
+            else TextBox.ForeColor = Color.Black;
         }
 
-        private void textBox1_TextChanged(object sender, System.EventArgs e)
+        private void TextBox_TextChanged(object sender, EventArgs e)
         {
-            //由于PlaceHolder可能是在加载完窗体之后赋值,所以在TextChanged中再次判断
-            if (PlaceHolder1 == "")
-            {
-                PlaceHolder1 = Text;
-            }
+            UserControlTextChanged?.Invoke(sender, new EventArgs());
         }
     }
-}
+}

+ 0 - 3
UAS-MES/CustomControl/TextBoxWithIcon/TextBoxWithPlaceHolder.resx

@@ -117,7 +117,4 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>False</value>
-  </metadata>
 </root>

+ 24 - 8
UAS-MES/Form1.Designer.cs

@@ -33,6 +33,7 @@
             this.button3 = new System.Windows.Forms.Button();
             this.button4 = new System.Windows.Forms.Button();
             this.progressBar1 = new System.Windows.Forms.ProgressBar();
+            this.textBoxWithPlaceHolder1 = new UAS_MES.CustomControl.TextBoxWithIcon.TextBoxWithPlaceHolder();
             this.SuspendLayout();
             // 
             // button1
@@ -57,9 +58,10 @@
             // 
             // button3
             // 
-            this.button3.Location = new System.Drawing.Point(305, 158);
+            this.button3.Location = new System.Drawing.Point(407, 198);
+            this.button3.Margin = new System.Windows.Forms.Padding(4);
             this.button3.Name = "button3";
-            this.button3.Size = new System.Drawing.Size(75, 23);
+            this.button3.Size = new System.Drawing.Size(100, 29);
             this.button3.TabIndex = 0;
             this.button3.Text = "button3";
             this.button3.UseVisualStyleBackColor = true;
@@ -67,9 +69,10 @@
             // 
             // button4
             // 
-            this.button4.Location = new System.Drawing.Point(410, 158);
+            this.button4.Location = new System.Drawing.Point(547, 198);
+            this.button4.Margin = new System.Windows.Forms.Padding(4);
             this.button4.Name = "button4";
-            this.button4.Size = new System.Drawing.Size(75, 23);
+            this.button4.Size = new System.Drawing.Size(100, 29);
             this.button4.TabIndex = 2;
             this.button4.Text = "button4";
             this.button4.UseVisualStyleBackColor = true;
@@ -78,19 +81,31 @@
             // progressBar1
             // 
             this.progressBar1.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
-            this.progressBar1.Location = new System.Drawing.Point(216, 90);
+            this.progressBar1.Location = new System.Drawing.Point(288, 112);
+            this.progressBar1.Margin = new System.Windows.Forms.Padding(4);
             this.progressBar1.Name = "progressBar1";
-            this.progressBar1.Size = new System.Drawing.Size(336, 23);
+            this.progressBar1.Size = new System.Drawing.Size(448, 29);
             this.progressBar1.TabIndex = 3;
             // 
+            // textBoxWithPlaceHolder1
+            // 
+            this.textBoxWithPlaceHolder1.BackColor = System.Drawing.Color.White;
+            this.textBoxWithPlaceHolder1.Location = new System.Drawing.Point(747, 292);
+            this.textBoxWithPlaceHolder1.Name = "textBoxWithPlaceHolder1";
+            this.textBoxWithPlaceHolder1.PlaceHolder = "123123";
+            this.textBoxWithPlaceHolder1.Size = new System.Drawing.Size(241, 25);
+            this.textBoxWithPlaceHolder1.TabIndex = 4;
+            // 
             // Form1
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(929, 590);
+            this.ClientSize = new System.Drawing.Size(1239, 738);
+            this.Controls.Add(this.textBoxWithPlaceHolder1);
             this.Controls.Add(this.progressBar1);
             this.Controls.Add(this.button4);
             this.Controls.Add(this.button3);
+            this.Margin = new System.Windows.Forms.Padding(4);
             this.Name = "Form1";
             this.Tag = "123123";
             this.Text = "Form1";
@@ -109,5 +124,6 @@
         private System.Windows.Forms.Button button3;
         private System.Windows.Forms.Button button4;
         private System.Windows.Forms.ProgressBar progressBar1;
+        private CustomControl.TextBoxWithIcon.TextBoxWithPlaceHolder textBoxWithPlaceHolder1;
     }
 }

+ 3 - 5
UAS-MES/Form1.cs

@@ -102,7 +102,8 @@ namespace UAS_MES
                 this.progressBar1.Value = e.ProgressPercentage;
                 //this.label1.Text = e.ProgressPercentage + "%";
             };
-            if (e.ProgressPercentage == 100) {
+            if (e.ProgressPercentage == 100)
+            {
                 ZipHelper.UnZip(@"H:\UAS_WinForm\UAS-MES\bin\Debug\icsharpcode-SharpZipLib-4ad264b.zip", @"D:\");
             }
             this.Invoke(act);
@@ -125,10 +126,7 @@ namespace UAS_MES
 
         private void button4_Click(object sender, EventArgs e)
         {
-            WebClient wc = new WebClient();
-            wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
-            wc.DownloadFileAsync(new Uri("http://218.17.158.219:8888/UAS_WinForm.zip"), "UAS_WinForm.zip");
-          
+            MessageBox.Show(textBoxWithPlaceHolder1.Text);
         }
     }
 

+ 13 - 20
UAS-MES/FunctionCode/Make/Make_TestCollection.Designer.cs

@@ -88,9 +88,9 @@
             this.ms_sncode = new UAS_MES.CustomControl.TextBoxWithIcon.SNCodeEnterTextBox();
             this.ma_softversion = new UAS_MES.CustomControl.ValueLabel.ValueLabel();
             this.ma_softversion_label = new System.Windows.Forms.Label();
-            this.Filter = new UAS_MES.CustomControl.TextBoxWithIcon.EnterTextBox();
             this.BadInfSource = new System.Windows.Forms.BindingSource(this.components);
             this.NoteForChange = new System.Windows.Forms.CheckBox();
+            this.Filter = new UAS_MES.CustomControl.TextBoxWithIcon.TextBoxWithPlaceHolder();
             this.panel2.SuspendLayout();
             this.panel1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.BadInfSource)).BeginInit();
@@ -793,23 +793,6 @@
             this.ma_softversion_label.TabIndex = 72;
             this.ma_softversion_label.Text = "软件版本";
             // 
-            // Filter
-            // 
-            this.Filter.AllPower = null;
-            this.Filter.BackColor = System.Drawing.Color.White;
-            this.Filter.Font = new System.Drawing.Font("宋体", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Filter.ID = null;
-            this.Filter.Location = new System.Drawing.Point(124, 355);
-            this.Filter.Margin = new System.Windows.Forms.Padding(4);
-            this.Filter.Name = "Filter";
-            this.Filter.Power = null;
-            this.Filter.Size = new System.Drawing.Size(233, 28);
-            this.Filter.Str = null;
-            this.Filter.Str1 = null;
-            this.Filter.Str2 = null;
-            this.Filter.TabIndex = 74;
-            this.Filter.TextChanged += new System.EventHandler(this.Filter_TextChanged);
-            // 
             // NoteForChange
             // 
             this.NoteForChange.AutoSize = true;
@@ -824,14 +807,24 @@
             this.NoteForChange.Text = "切换工单提示";
             this.NoteForChange.UseVisualStyleBackColor = true;
             // 
+            // Filter
+            // 
+            this.Filter.Font = new System.Drawing.Font("宋体", 10.8F);
+            this.Filter.Location = new System.Drawing.Point(124, 357);
+            this.Filter.Name = "Filter";
+            this.Filter.PlaceHolder = "查询不良";
+            this.Filter.Size = new System.Drawing.Size(234, 28);
+            this.Filter.TabIndex = 76;
+            this.Filter.UserControlTextChanged += new UAS_MES.CustomControl.TextBoxWithIcon.TextBoxWithPlaceHolder.OnTextChange(this.Filter_UserControlTextChanged);
+            // 
             // Make_TestCollection
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.SystemColors.Control;
             this.ClientSize = new System.Drawing.Size(1149, 700);
-            this.Controls.Add(this.NoteForChange);
             this.Controls.Add(this.Filter);
+            this.Controls.Add(this.NoteForChange);
             this.Controls.Add(this.ma_softversion);
             this.Controls.Add(this.ma_softversion_label);
             this.Controls.Add(this.panel1);
@@ -945,8 +938,8 @@
         private System.Windows.Forms.Label ma_softversion_label;
         private System.Windows.Forms.ColumnHeader columnHeader9;
         private System.Windows.Forms.ColumnHeader columnHeader10;
-        private CustomControl.TextBoxWithIcon.EnterTextBox Filter;
         private System.Windows.Forms.BindingSource BadInfSource;
         private System.Windows.Forms.CheckBox NoteForChange;
+        private CustomControl.TextBoxWithIcon.TextBoxWithPlaceHolder Filter;
     }
 }

+ 26 - 19
UAS-MES/FunctionCode/Make/Make_TestCollection.cs

@@ -677,30 +677,37 @@ namespace UAS_MES.Make
             LoadBadGroupData();
         }
 
-        private void Filter_TextChanged(object sender, EventArgs e)
+        private void Filter_UserControlTextChanged(object sender, EventArgs e)
         {
-            DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
-            DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
-            for (int i = 0; i < dr.Length; i++)
+            try
             {
-                dt.Rows.Add(dr[i].ItemArray);
-            }
-            WaitRejectList.Items.Clear();
-            WaitRejectList.BeginUpdate();
-            for (int i = 0; i < dt.Rows.Count; i++)
-            {
-                if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
+                DataRow[] dr = (BadInfSource.DataSource as DataTable).Select("bc_code like '%" + Filter.Text + "%' or bc_name like '%" + Filter.Text + "%'");
+                DataTable dt = (BadInfSource.DataSource as DataTable).Clone();
+                for (int i = 0; i < dr.Length; i++)
                 {
-                    ListViewItem lvi = new ListViewItem();
-                    //第一列是勾选列,设置列头文本为空
-                    lvi.Text = "";
-                    WaitList.Add(dt.Rows[i]["bc_code"].ToString());
-                    for (int j = 0; j < dt.Columns.Count; j++)
-                        lvi.SubItems.Add(dt.Rows[i][j].ToString());
-                    WaitRejectList.Items.Add(lvi);
+                    dt.Rows.Add(dr[i].ItemArray);
+                }
+                WaitRejectList.Items.Clear();
+                WaitRejectList.BeginUpdate();
+                for (int i = 0; i < dt.Rows.Count; i++)
+                {
+                    if (!ChoosedList.Contains(dt.Rows[i]["bc_code"].ToString()))
+                    {
+                        ListViewItem lvi = new ListViewItem();
+                        //第一列是勾选列,设置列头文本为空
+                        lvi.Text = "";
+                        WaitList.Add(dt.Rows[i]["bc_code"].ToString());
+                        for (int j = 0; j < dt.Columns.Count; j++)
+                            lvi.SubItems.Add(dt.Rows[i][j].ToString());
+                        WaitRejectList.Items.Add(lvi);
+                    }
                 }
+                WaitRejectList.EndUpdate();
+            }
+            catch (Exception)
+            {
+
             }
-            WaitRejectList.EndUpdate();
         }
     }
 }