I'm working on a windows app at the moment and (thankfully) I'm heading down the home stretch. I'm now at the point that end users are testing the app and requesting changes.
The app is going to take care of customer maintenance/promotions for our company so it has all of the usual things, Names, Addresses, Email Addressees, you get the point. To make a long story short, the users want the TextBox where they type in an Email Address to extend while they are typing to show the entire email address, no matter how long it is.
"Think about in Excel, when you're typing in a cell and what you're typing in is longer than the width of a cell, the cell just extends until you tab out of it."
I thought that between all of the .NET source available on the interwebs, the .NET Framework, and the Infragistics controls we use that I would be able to find this functionality somewhere. Well, I was wrong!
The solution I came up with was a simple one though, I would just use the ToolTip control provided with .NET 2.0 to display a ToolTip directly under the TextBox that would dynamically change while the user was typing. So that's what I did, and here's how I did it:
On the TextBox.Enter event
// Shows the ToolTip if the TextBox is not empty
searchToolTip.Show(this.txtEmail.Text, this, 115, 395);
On the TextBox.KeyPress event
if (char.IsLetterOrDigit((char)e.KeyChar) ||
char.IsPunctuation((char)e.KeyChar))
{
// Show the ToolTip with the next TextBox.Text
searchToolTip.Show(txtEmail.Text + e.KeyChar.ToString(),
this, 115, 395);
}
else
{
// Show the Tooltip without the KeyChar added
// if a garbage key is pressed
searchToolTip.Show(txtEmail.Text,
this, 115, 395);
}
And finally, on the TextBox.Leave event
//Hide the tooltip
searchToolTip.Show("", this,
Screen.PrimaryScreen.Bounds.Right,
Screen.PrimaryScreen.Bounds.Bottom);
0 comments:
Post a Comment