Monday, February 19, 2007

Windows Vista,  has a great feature that has been introduced within the user interface.  Textbox fields when they are empty display their label, as follows:

What a great idea to implement this feature on Windows mobile; this would save vast amount of screen space as textbox labels seem to utilise lots of screen space (certainly on the LOB apps I write).

So with half an hour to kill this morning I produced a quick proof of concept that achieve this.  

Screenshot below, showing textbox not in focus.   Notice label colour is gray.

Screenshot below, showing textbox in focus

The code behind this is as follows, just implementing the GotFocus and LostFocus events on the textbox control:

private bool inlabelmode = true;

private string labeltext = "Our Box";

public Form1()

{

InitializeComponent();

labelon();

this.trackBar1.Focus();

}

private void labelon()

{

this.textBox1.ForeColor = Color.Gray;

this.textBox1.Text = labeltext;

inlabelmode = true;

}

private void labeloff()

{

this.textBox1.Text = "";

this.textBox1.ForeColor = Color.Red;

inlabelmode = false;

}

private void textBox1_GotFocus(object sender, EventArgs e)

{

if (inlabelmode) labeloff();

}

private void textBox1_LostFocus(object sender, EventArgs e)

{

if (this.textBox1.Text == "") labelon();

}

 

Anyhow,   it all needs wrapping up into a nice user control, but I thought I'd put this up to share.

 

 

Monday, February 19, 2007 10:43:45 AM UTC  #    Comments [5]  | 
Tuesday, February 20, 2007 11:26:39 PM UTC
Nice little piece of code... good way to save screen resource space!
Wednesday, February 21, 2007 11:05:00 AM UTC
This kind of control will only really work where the text won't be pre-populated, otherwise the user will just see a list of text boxes with text in them and they won't know what's supposed to go in them.

The one in IE7 is a good space saver, but it ony shows what search engine it will be using which in a way the user doesn't need to know.

I'd suggest to be very careful when using a control like this and use it sporadically.
Wednesday, February 21, 2007 2:14:10 PM UTC
I agree it is useful. It is not Vista-only, it works on XP as well. And I have wrapped it in a cotnrol last year, FYI:
http://www.danielmoth.com/Blog/2006/07/textbox-with-cue-banner-support-for.html
Wednesday, February 21, 2007 2:55:30 PM UTC
Thanks Daniel.

Great to see and thanks for the link.
Richard
Thursday, March 01, 2007 12:43:17 AM UTC
Neat idea, but I personally would spend time developing a custom control for this, since textboxes in mobile apps are generally used to display data, and without a caption you'd never know what was what.
Comments are closed.

Theme design by Jelle Druyts

Pick a theme: