Winforms 如何将.NET TextBoxRenderer与TextBoxState.Hot一起使用以绘制热文本框?

Winforms 如何将.NET TextBoxRenderer与TextBoxState.Hot一起使用以绘制热文本框?,winforms,visual-styles,Winforms,Visual Styles,我正在尝试使用渲染“热”文本框: TextBoxRenderer.DrawTextBox(e.Graphics, rectangle, TextBoxState.Hot); 除了不起作用外,它不会将文本框渲染为热状态 TextBoxState.Selected不会呈现为选中状态 TextBoxState.Hot不会渲染为Hot 如何使TextBoxRenderer.DrawTextBox(…,Hot)呈现为Hot 相关但不同的问题: 如何使TextBoxRenderer.DrawText

我正在尝试使用渲染“热”文本框:

TextBoxRenderer.DrawTextBox(e.Graphics, rectangle, TextBoxState.Hot);
除了不起作用外,它不会将文本框渲染为热状态

  • TextBoxState.Selected
    不会呈现为选中状态
  • TextBoxState.Hot
    不会渲染为Hot

如何使
TextBoxRenderer.DrawTextBox(…,Hot)
呈现为
Hot

相关但不同的问题:
如何使
TextBoxRenderer.DrawTextBox(…,选中)
呈现为
选中

似乎
TextBoxRenderer
使用
EP\u backgroundithborder
,而
EP\u EDITBORDER\u NOSCROLL
通常由
TextBox
控件使用


(尝试从
VisualStyleElement
获取元素很有诱惑力,但是
EP\u EDITBORDER\u NOSCROLL
没有嵌套类。所以数字常量是6和3。)

我不想继续破坏你的一天,但MSDN文章指出:“Windows XP Home Edition、Windows XP Professional x64 Edition、Windows Server 2003平台注意:视觉样式仅在这些平台上受支持。”@LarsTech这是一个文档问题。他们可能试图说Windows XP Starter Edition(不支持主题)不支持视觉样式。他们本可以在概念上更好地表述它,说:“不支持视觉样式的操作系统不支持VisualStyleRenderer。”如果您想让文档保持真实,则Windows 7和Windows Server 2008 R2()上不支持任务计划程序API。这应该可以正常工作,但是.NET的UxTheme包装器无法验证特定的部件/状态组合。我成功地使我的项目能够正常工作。
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);
  }
}