7

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?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
  • I hate to keep ruining your day, but the MSDN article states: "Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Platform Note: Visual styles are supported only on these platforms." – LarsTech Dec 12 '11 at 17:37
  • 1
    @LarsTech That's a a documentation issue. They're probably trying to say that visual styles are unsupported on Windows XP Starter Edition (which doesn't support themes). They could have phrased it conceptually better, saying, "VisualStyleRenderer is unsupported on operating systems that don't support visual styles." If you want to hold the documentation literally true, then the Task Scheduler API is unsupported on Windows 7 and Windows Server 2008 R2 (http://msdn.microsoft.com/en-us/library/windows/desktop/aa383614(v=vs.85).aspx). – Ian Boyd Dec 12 '11 at 18:05

1 Answers1

3

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.)

Ian Goldby
  • 5,609
  • 1
  • 45
  • 81
  • 1
    This should work as provided, however .NET's UxTheme wrapper couldn't validate that specific part/state combination. I had success getting my project to work with [this solution on CodeProject](https://www.codeproject.com/Articles/18603/Advanced-UxTheme-wrapper). – Chance Snow Feb 14 '17 at 16:49