- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 ComboBox,我设置了 DrawMode = DrawMode.OwnerDrawFixed。然后我处理 OnDrawItem 事件,一切正常。但是,它看起来与标准 ComboBox 非常不同,因为我的 ComboBox 似乎没有使用 VisualStyles 呈现。我需要做些什么来专门为我的所有者绘制的控件启用 VisualStyle 呈现吗?我已经在我的控件上尝试过 SetWindowTheme,但我不确定要发送什么主题类。任何帮助将非常感激。谢谢!
最佳答案
owner-draw 的缺点是,当您打开它时,所有者(您)必须绘制所有内容。你几乎完全靠自己。
如果您想要视觉样式,则必须直接调用 VisualStyles API 来执行您想要的操作。如果要显示选中、聚焦、启用/禁用状态,则必须编写代码来处理所有这些状态。
这不是您的组合框问题的直接答案,但作为如何使用 VisualStyles 的示例,下面是我如何在所有者绘制的 TreeView 中使用 VisualStyles 来绘制加号/减号图标:
// Draw Expand (plus/minus) icon if required
if (ShowPlusMinus && e.Node.Nodes.Count > 0)
{
// Use the VisualStyles renderer to use the proper OS-defined glyphs
Rectangle expandRect = new Rectangle(iconLeft-1, midY - 7, 16, 16);
VisualStyleElement element = (e.Node.IsExpanded) ? VisualStyleElement.TreeView.Glyph.Opened
: VisualStyleElement.TreeView.Glyph.Closed;
VisualStyleRenderer renderer = new VisualStyleRenderer(element);
renderer.DrawBackground(e.Graphics, expandRect);
}
关于c# - OwnerDraw ComboBox with VisualStyles,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1919887/
我只是在使用 Winforms 处理 .NET 提供的视觉样式,我遇到了一个问题。我只是执行这段代码,从自定义面板的 OnPaint 方法调用,没有什么特别的。 private void DrawBo
Microsoft 的 winforms 视觉样式一直让我感到困惑。 我试图让 Panel 位于 TreeView 旁边,并且只有相同的 VisualStyle 边框。 如您所见,TreeView 边
我有一个 ComboBox,我设置了 DrawMode = DrawMode.OwnerDrawFixed。然后我处理 OnDrawItem 事件,一切正常。但是,它看起来与标准 ComboBox 非
我是一名优秀的程序员,十分优秀!