[英]Highlight a textbox when there is no input
I would like to highlight a textbox when there's no input, here is my sample code 我想在没有输入的情况下突出显示一个文本框,这是我的示例代码
if (textBox2.Text == "")
{
MessageBox.Show("Please put your password");
textBox2.Focus();
}
I want to highlight it as it like glows, but it only set the Ibeam cursor unto the textbox, please help me, thanks in advance :) 我想像发光一样突出显示它,但是它只将Ibeam光标设置在文本框中,请帮助我,在此先感谢:)
您可以更改文本框的背景颜色 。
textBox2.BackColor = Color.Yellow;
Try using Winforms error provider: 尝试使用Winforms错误提供程序:
if (textBox2.Text == "")
{
errorProvider1.SetError(textBox2, "Please put your password");
textBox2.BackColor = Color.Red; //to add high light
}
See : C# ErrorProvider 请参阅: C#ErrorProvider
Regards 问候
You need to Add these lines to the CSS:- 您需要将以下行添加到CSS:
.glow:focus {
border-color: #6EA2DE;
box-shadow: 0px 0px 10px #6EA2DE;
}
and in your form you can add a CssClass
attribute:- 在您的表单中,您可以添加
CssClass
属性:
<asp:TextBox id="textBox2" CssClass="glow" runat="server"/>
Try this; 尝试这个;
if (textBox1.Text == "")
{
MessageBox.Show("Please put your password");
textBox1.Focus();
textBox1.BorderThickness = new Thickness(2, 2, 2, 2);
textBox1.BorderBrush = Brushes.Red;
textBox1.Background = Brushes.Beige;
}
You need to set the css border properties on focus of the textbox. 您需要在文本框的焦点上设置css边框属性。 Something like this:
像这样:
border-color: whatever color you want ; 边框颜色: 您想要的任何颜色 ;
} }
You can set whatever css properties you in this way. 您可以通过这种方式设置任何CSS属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.