Skip to content

akorb/TextBox-with-Placeholder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 

Repository files navigation

TextBox with Placeholder

In many cases it's very nice to use a placeholder instead of a label explaining the content. With HTML5 this is very easy and just a single attribute. Unfortunately, no .NET control provides any similar attribute.

There are already two methods to do that.

Method 1

Windows has a built-in function for adding a placeholder. To use it, you have to use P/Invoke.
See StackOverflow: http://stackoverflow.com/a/4902969

This has a slightly different behavior than all other methods. If you click on the text box a second time, the placeholder disappears. If you then leave the control with the mouse, it will be shown again. No option to change this, but I doubt that's a problem.

Method 2

This method is pretty clever. The placeholder actually isn't inside of the text box, it's just drawn over it.
See CodeProject: http://www.codeproject.com/Articles/319910/Custom-TextBox-with-watermark

Mine

Mine overrides the behavior of TextBox and implements the placeholder on top.

Overview

Method 1 Method 2 Mine
Build-in Customizable Customizable
Mono

Mono support
Method 1 doesn't work with Mono because it uses the Win32 API.
Method 2 throws an exception.
Mine works almost perfectly. Only the cursor is able to move through the placeholder with clicking. I don't know why yet.

Customizable
Method 1 is not customizable.
Method 2 is very well customizable. Additional to mine it can set the placeholder color while focused.
Mine can do the same as Method 2, except setting the color while focused.

Recommendations
Use Method 1 if you only want to support Windows, are fine with its behavior and the default light grey color is fine.
Use Method 2 if you only want to support Windows and need to set the color of the placeholder while focused.
Use mine method if you want to support cross platform.

About

TextBox with additional placeholder functionality.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages