winforms - 如何使用.NET TextBoxRenderer和TextBoxState.Hot来绘制热文本框?

标签 winforms visual-styles

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

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

除了它不起作用之外,它不会将文本框渲染得很热。

  • TextBoxState.Selected 未呈现为选定状态
  • TextBoxState.Hot 未呈现为热

enter image description here

如何使 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/

相关文章:

c# - 使用 Linq 关闭所有 MDI 子窗口

c# - 有没有办法在最小化进程时也从进程中获取屏幕截图?

c# - 推荐的 c# winform 控件包

c# - 在 C# 中检测 wifi 连接

c# - 没有启用视觉样式的 TabRenderer?

c++ - 如何更改 Win32 API 应用程序中的控件主题?

c# - 按钮自动设置 DialogResult?

winforms - 将自定义视觉样式 (.msstyle) 应用到单个 Winforms 应用程序

wpf - 更改 WPF 应用程序 list ?

c# - 视觉风格独立绘图