Winforms 如何创建水印文本框

Winforms 如何创建水印文本框,winforms,textbox,Winforms,Textbox,如何在winForm中创建水印文本框 我想在我的应用程序登录屏幕中使用如果您想让它变得简单,您可以这样做: string xyz = "Enter User Name Here.."; private void textBox_Leave(object sender, EventArgs e) { { if (textBox.Text.Length.Equals(0)) { te

如何在winForm中创建水印文本框


我想在我的应用程序登录屏幕中使用

如果您想让它变得简单,您可以这样做:

  string xyz = "Enter User Name Here.."; 
    private void textBox_Leave(object sender, EventArgs e)
    {
        {
            if (textBox.Text.Length.Equals(0))
            {
                textBox.Text = xyz;
            }
        }
    }

    private void textBox_Click(object sender, EventArgs e)
    {
        {
            if (textBox.Text.Equals(xyz))
            {
                textBox.Clear();
            }
        }
    }
并在form_load事件中添加以下行:

    textBox.Text = xyz;
    textBox.Select(textBox.Text.Length, 0);

谢谢david,但我不想使用自定义控件可能重复的