Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
In many cases, a TextBox with an easy Placeholder property would be very helpful especially when you want the user to filter a
ListView or ListBox by search terms.
So, I never found a really good one. I know there exists a very easy method with only one SendMessage method, but I don't like it
because the placeholder is hard to differentiate with the actually typed text and I don't like these message things very much, too
many things can go wrong.
Now I created my own control and my destination is that it is very easy to use.
The difference to the usual TextBox is it that there are three new properties:
PlaceholderText: It's not hard to guess what this property does. It defines the Placeholder text which will get
displayed if the TextBox is empty.
https://www.codeproject.com/Tips/589115/TextBox-with-Placeholder 1/5
4/29/2018 TextBox with Placeholder - CodeProject
IsPlaceholderActive: Through this property, you can always check if the textbox shows the placeholder or real text
at the moment.
The Text property is not accessible with the designer. That's to keep the standard. The placeholder should always be seen before you
type any text in the TextBox.
Points of Interest
It's a very well written code. I recommend you read it, there are many comments and maybe you have a suggestion.
I hope you like my control and when you have any suggestions or have found a bug, please let me know!
History
v1.5
Fixed behavior with pressing Ctrl+A while placeholder is active
MaxLength working now
Fixed crashes if setting Text programmatically
v1.4
Fixed bugs reported by Member 12412017
Fixed bug reported by Member 13208153
v1.3
Fixed bug: Font can be changed now - Thanks to Member 11133660
Improved internal logic
Removed IsItalics
Renamed PlaceholderInsideChanged to PlaceholderActiveChanged
v1.2
Improved internal logic
Removed sealed
Added Placeholder category to designer for better overview
Fixed some comments
v1.1
Added PlaceholderInsideChanged event
Fixed bug that new MouseDownEvents never occur
Prevents user to go through placeholder with arrow keys
License
https://www.codeproject.com/Tips/589115/TextBox-with-Placeholder 2/5
4/29/2018 TextBox with Placeholder - CodeProject
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
Share
TWITTER FACEBOOK
MCMS Placeholder Content Web Part Wind River Helix Device Cloud Application
Deployment: POC Retail Vending Machine
Building a New Parse Server & MongoDB Atlas- Angular 5 – Reactive Forms with Dynamic
Based Application FormArray and Simple Validation
https://www.codeproject.com/Tips/589115/TextBox-with-Placeholder 3/5
4/29/2018 TextBox with Placeholder - CodeProject
Search Comments
Bug 3 - fails if CharacterCasing set to Upper or Lower, but Place Holder Text is in another case.
VBNetHack 2-Jul-17 3:52
Re: Bug 3 - fails if CharacterCasing set to Upper or Lower, but Place Holder Text is in another case.
AndyFTW 15-Feb-18 5:08
bug 2
Member 12412017 17-Jun-17 9:44
Re: bug 2
AndyFTW 15-Feb-18 5:07
bug
Member 12412017 17-Jun-17 0:47
My vote of 5
Maxwolf Goodliffe 12-Dec-14 7:08
https://www.codeproject.com/Tips/589115/TextBox-with-Placeholder 4/5
4/29/2018 TextBox with Placeholder - CodeProject
My vote of 5
Meng FanRui 3-Sep-13 23:51
My vote of 2
FernandoUY 2-Sep-13 14:09
Re: My vote of 2
AndyFTW 6-Sep-13 2:22
Re: My vote of 2
FernandoUY 6-Sep-13 8:05
Not an article
OriginalGriff 16-May-13 2:29
Refresh 1
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise | Privacy | Terms of Use | Mobile Article Copyright 2013 by AndyFTW
Select Language ▼
Web04-2016 | 2.8.180417.1 | Last Updated 29 Apr 2018 Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid
https://www.codeproject.com/Tips/589115/TextBox-with-Placeholder 5/5