How to give an initial value to textBox?

前端 未结 4 1484
谎友^
谎友^ 2021-01-14 17:03

I want my C# program to have initial values for its textboxes. For example, in one of the textboxes, it should say \"Please enter your name\"

4条回答
  •  感情败类
    2021-01-14 17:22

    This is how I finally did it:

    Boolean first_time_click = true;
    
    private void Form1_Load(object sender, EventArgs e)
            {
                textBox1.ForeColor = System.Drawing.Color.Gray;
                textBox1.Text = "Enter the Text";
            }
    
    private void For_First_Click()
            {
                if (first_time_click)
                {
                    textBox1.Clear();
                    textBox1.ForeColor = textBox1.ForeColor = SystemColors.WindowText;
                }
                first_time_click = false;
            }
    
    private void textBox1_Click(object sender, EventArgs e)
            {
                For_First_Click();
            }
    

提交回复
热议问题