Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i am trying to use TextBoxRenderer to render a "hot" text box:

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

except that it doesn't work, it doesn't render the text box as hot.

  • TextBoxState.Selected doesn't render as selected
  • TextBoxState.Hot doesn't render as hot

enter image description here

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

Related but different question:

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

like image 916
Ian Boyd Avatar asked Dec 12 '11 16:12

Ian Boyd


1 Answers

It seems that TextBoxRenderer uses EP_BACKGROUNDWITHBORDER, whereas EP_EDITBORDER_NOSCROLL is typically used by TextBox controls[1].

if (VisualStyleRenderer.IsSupported)
{
  // Use the text control's 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 the element from VisualStyleElement but there's no nested class for EP_EDITBORDER_NOSCROLL. So numeric constants 6 and 3 it is.)

like image 67
Ian Goldby Avatar answered Nov 03 '22 21:11

Ian Goldby