gpt4 book ai didi

c# - OwnerDraw ComboBox with VisualStyles

转载 作者:太空狗 更新时间:2023-10-29 21:37:08 26 4
gpt4 key购买 nike

我有一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com