Jon*_*ury 6 c# combobox winforms
我有一个ComboBox,我设置了DrawMode = DrawMode.OwnerDrawFixed.然后我处理OnDrawItem事件,一切都很完美.但是,它看起来与标准的ComboBox非常不同,因为我似乎没有使用VisualStyles渲染.我是否需要做一些事情来专门为我的所有者绘制控件启用VisualStyle渲染?我在我的控制下尝试过SetWindowTheme,但我不确定要发送什么样的主题类.任何帮助将非常感激.谢谢!
所有者绘制的缺点是当你打开它时,所有者(你)必须绘制所有东西.你几乎完全依靠自己.
如果你想要视觉样式,那么你必须直接调用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);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2410 次 |
最近记录: |