如何使用.NET TextBoxRenderer与TextBoxState.Hot绘制热文本框?

Ian*_*oyd 6 winforms visual-styles

我试图用来TextBoxRenderer呈现一个"热"文本框:

TextBoxRenderer.DrawTextBox(e.Graphics, rectangle, TextBoxState.Hot);
Run Code Online (Sandbox Code Playgroud)

除了它不起作用,它不会使文本框变为热.

  • TextBoxState.Selected 不会呈现为选中状态
  • TextBoxState.Hot 不会变得很热

在此输入图像描述

我如何TextBoxRenderer.DrawTextBox(..., Hot)渲染为Hot

相关但不同的问题:

我如何TextBoxRenderer.DrawTextBox(..., Selected)渲染为Selected

Ian*_*dby 3

似乎TextBoxRenderer使用EP_BACKGROUNDWITHBORDER,而EP_EDITBORDER_NOSCROLL通常由TextBox控件使用[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);
  }
}
Run Code Online (Sandbox Code Playgroud)

(尝试从中获取元素很诱人VisualStyleElement,但没有 的嵌套类EP_EDITBORDER_NOSCROLL。所以它是数字常量 6 和 3。)