I'm trying to make ghost text in a text box on a C# form in Visual Studio 2010, but haven't been able to figure out how to do it, if anyone can help it would be greatly appreciated.
If at all possible, I would like the form to not recognize the ghost text as actual input data (so my try/catch processes still work)
3 replies to this topic
#1
Posted 28 September 2011 - 12:29 PM
|
|
|
#2
Posted 28 September 2011 - 12:54 PM
Why not use the text color as the flag. When the user starts typing in the field, change the text color to normal. Refuse to process the data of "ghosted" text.
#3
Posted 29 September 2011 - 07:26 AM
#4
Posted 29 September 2011 - 03:17 PM
I figured it out with a little networking. I'll post what I did up here if anyone is interested
set whatever message you want in the textbox and set the ForeColor to GrayText in the object's default settings then add this to the code for the textbox in question:
[/HR]
private void Object_Enter(object sender, EventArgs e)
{
Object.Text = "";
Object.ForeColor = SystemColors.WindowText;
}
private void Object_Leave(object sender, EventArgs e)
{
if (Object.Text != "") //Not blank
{
}
else //missing data
{
Object.Text = "Ghost-text";
Object.ForeColor = SystemColors.GrayText;
}
}
[/HR]
After that, it's just a matter of setting your try-catch or if-else statements to ignore everything with the "ForeColor = SystemColors.GrayText" setting, as WingedPanther had pointed out.
I'm sure there are easier ways to do this, but it's what I was able to throw together in a night of tinkering. Thanks for helping. :)
set whatever message you want in the textbox and set the ForeColor to GrayText in the object's default settings then add this to the code for the textbox in question:
[/HR]
private void Object_Enter(object sender, EventArgs e)
{
Object.Text = "";
Object.ForeColor = SystemColors.WindowText;
}
private void Object_Leave(object sender, EventArgs e)
{
if (Object.Text != "") //Not blank
{
}
else //missing data
{
Object.Text = "Ghost-text";
Object.ForeColor = SystemColors.GrayText;
}
}
[/HR]
After that, it's just a matter of setting your try-catch or if-else statements to ignore everything with the "ForeColor = SystemColors.GrayText" setting, as WingedPanther had pointed out.
I'm sure there are easier ways to do this, but it's what I was able to throw together in a night of tinkering. Thanks for helping. :)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









