How to use .NET TextBoxRenderer with TextBoxState.Hot to draw a hot text field?

I am trying to use a TextBoxRenderer to display a hot text field:

 TextBoxRenderer.DrawTextBox(e.Graphics, rectangle, TextBoxState.Hot); 

except that it does not work, it does not display the text field as hot.

  • TextBoxState.Selected does not appear as selected
  • TextBoxState.Hot does not display as hot

enter image description here

How to make TextBoxRenderer.DrawTextBox(..., Hot) render as Hot ?

A related but different question:

How to make TextBoxRenderer.DrawTextBox(..., Selected) render as Selected ?

+6
source share
1 answer

It seems that TextBoxRenderer uses EP_BACKGROUNDWITHBORDER , while EP_EDITBORDER_NOSCROLL usually used by TextBox controls [1] .

 if (VisualStyleRenderer.IsSupported) { // Use the text control focus rectangle. // EP_EDITBORDER_NOSCROLL, EPSN_FOCUSED VisualStyleElement element = VisualStyleElement.CreateElement("EDIT", 6, 3); if (VisualStyleRenderer.IsElementDefined(element)) { VisualStyleRenderer renderer = new VisualStyleRenderer(element); renderer.DrawBackground(e.Graphics, ClientRectangle); } } 

(It's tempting to try to get an element from VisualStyleElement , but there is no nested class for EP_EDITBORDER_NOSCROLL . So the numeric constants 6 and 3 are.)

+2
source

Source: https://habr.com/ru/post/903605/


All Articles