question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PlaceholderText API addition to TextBox control

See original GitHub issue

With the following PR (https://github.com/dotnet/winforms/pull/96 -> moved to https://github.com/dotnet/winforms/pull/238) we have proposed addition of new property to the TextBox control called PlaceholderText. The property accepts string which will be drawn when the control has no text it in and is not on focus. Quite useful to indicate what is the expected input.

Rationale

Currently, in order to provide guidance for the users what input is expected in a text field, the only option is to have a label next to the TextBox control. However, there are cases, where label is not appropriate and it is much more user friendly to have a placeholder text in the TextBox itself, to guide the user as to what input is expected. Think of scenarios for “Enter your username/password”

Proposed API

public string PlaceholderText {get; set;}

Description

A single public property called PlaceholderText is introduced, with no value. When the property is set, AND the TextBox has no Text set nor focus, the string from the PlaceholderText will be drawn in the TextBox control, using the SystemColors.GrayText. Once the property value is changed the new text will be drawn, if currently visible. Once the user focuses on the control, the text disappears. Different text alignments and RightToLeft are taken into consideration when the PlaceholderText is being drawn. In addition, it also works in Multiline mode.

In addition AccessibilityObject has been implemented to return the PlaceholderText when the Text is empty, hence screen readers read the PlaceholderText value and guide the users to what is expected from them as input.

On the bottom left side of the image you can see a TextBox with PlaceholderText drawn. image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:36 (29 by maintainers)

github_iconTop GitHub Comments

5reactions
wjkcommented, Dec 4, 2018

Is there any reason why we shouldn’t just use the EM_SETCUEBANNER message available since Windows Vista to do this? (I know that compatibility with really old systems — namely, Windows XP — would be negatively affected were we to do it this way, but I thought we don’t support anything before Windows 7 anyway.)

3reactions
stefanov-stefancommented, Jan 7, 2019

Hey guys, thanks for pinging me and for the inspiration. I was not sure what I should provide, so it helped a lot.

Rationale

Currently, in order to provide guidance for the users what input is expected in a text field, the only option is to have a label next to the TextBox control. However, there are cases, where label is not appropriate and it is much more user friendly to have a placeholder text in the TextBox itself, to guide the user as to what input is expected. Think of scenarios for “Enter your username/password”

Proposed API

public string PlaceholderText {get; set;}

Description

A single public property called PlaceholderText is introduced, with no value. When the property is set, AND the TextBox has no Text set nor focus, the string from the PlaceholderText will be drawn in the TextBox control, using the SystemColors.GrayText. Once the property value is changed the new text will be drawn, if currently visible. Once the user focuses on the control, the text disappears. Different text alignments and RightToLeft are taken into consideration when the PlaceholderText is being drawn. In addition, it also works in Multiline mode.

In addition AccessibilityObject has been implemented to return the PlaceholderText when the Text is empty, hence screen readers read the PlaceholderText value and guide the users to what is expected from them as input.

On the bottom left side of the image you can see a TextBox with PlaceholderText drawn. image

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Adding placeholder text to textbox
I.e. if the textbox has no text, then it adds the text Enter some text here , when the user clicks on it...
Read more >
TextBox.PlaceholderText Property (System.Windows.Forms)
Gets or sets the text that is displayed when the control has no text and does not have the focus.
Read more >
TextBoxModel API in JavaScript TextBox API control
Specifies the text that is shown as a hint/placeholder until the user focus or enter a value in Textbox. The property is depending...
Read more >
Placeholder Text Box - WPF UI COMPONENT WORKSHOP
Learn how to create a placeholder text box in WPF. Additional concepts covered include dependency properties, custom control inheritance, ...
Read more >
How to add placeholder text to a textarea
Placeholder text is text found inside a textarea or input tag to prompt users. Learn how set up textarea placeholder in TinyMCE and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found