dotnet/winforms

Correct `TextBox.PlaceHolderText` implementations

Open

#4.089 geöffnet am 12. Okt. 2020

Auf GitHub ansehen
 (8 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)C# (922 Forks)batch import
:beetle: bughelp wantedtenet-performance

Repository-Metriken

Stars
 (4.100 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 14T 22h) (56 gemergte PRs in 30 T)

Beschreibung

Is your feature request related to a problem? Please describe.

The current implementation of TextBox.TextPlaceHolderText API added in #96/#238 suffers from a number of deficiencies and shortcomings as listed below.

  1. It is unaware of the native implementation and visually inconsistent with it:

    textBox1.PlaceholderText = "Custom!";
    SendMessageW(textBox1.Handle, EM_SETCUEBANNER, IntPtr.Zero, "NATIVE PlaceHolder..");
    

    image

  2. It is visually inconsistent with the native implementation:

    • This implementation - TextBox control with PlaceHolderText property set: image

    • Native implementation - TextBox control with the placeholder text set via the EM_SETCUEBANNER: image

      • different locations,
      • different font colours, and
      • different shortening strategies.
  3. The current implementation is also not UIA aware:

    • This implementation image
    • Native implementation: image

Describe the solution you'd like and alternatives you've considered

  • Keep the existing public API surface in tact
  • Rework PlaceHolderText implementation as follows:
    • Use Win32 API EM_SETCUEBANNER for single line textboxes when visual styles are enabled.
    • Align location of the custom drawn text with the position of the Win32 implementation.
    • Align the font of the custom drawn text with the size/style of the Win32 implementation.
    • Align the color of the custom drawn text with the color of the Win32 implementation.
    • Align the shortening strategy of the custom drawn text with the color of the Win32 implementation - i.e. clip the text instead of "..."
  • Fallback to the current implementation in the following situations:
    • TextBox.Multiline = true.
    • Visual styles are disabled.

❗ Tests must verify correct behaviours when switching single<-->multiline.

❕ Accessibility support for the custom drawn text at this stage remains optional.

Contributor Guide