我正在尝试使用TextBoxRenderer
渲染“热”文本框:
TextBoxRenderer.DrawTextBox(e.Graphics, rectangle, TextBoxState.Hot);
除了它不起作用之外,它不会将文本框渲染得很热。
TextBoxState.Selected
未呈现为选定状态TextBoxState.Hot
未呈现为热
如何使 TextBoxRenderer.DrawTextBox(..., Hot)
渲染为 Hot
?
相关但不同的问题:
如何使 TextBoxRenderer.DrawTextBox(..., Selected)
呈现为 Selected
?
最佳答案
似乎 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
获取元素很诱人,但 EP_EDITBORDER_NOSCROLL
没有嵌套类。所以是数字常量 6 和 3。)
关于winforms - 如何使用.NET TextBoxRenderer和TextBoxState.Hot来绘制热文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8477522/