7

我正在尝试使用TextBoxRenderer呈现“热”文本框:

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

除了它不起作用之外,它不会将文本框呈现为热。

  • TextBoxState.Selected不呈现为选中状态
  • TextBoxState.Hot没有渲染得那么热

在此处输入图像描述

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

相关但不同的问题:

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

4

1 回答 1

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);
  }
}

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

于 2017-01-25T10:20:16.323 回答