OwnerDraw ComboBox与VisualStyles [英] OwnerDraw ComboBox with VisualStyles

查看:188
本文介绍了OwnerDraw ComboBox与VisualStyles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ComboBox,我已设置 DrawMode = DrawMode.OwnerDrawFixed 。然后我处理OnDrawItem事件,一切工作完美。然而,它看起来与标准ComboBox非常不同,因为我似乎不使用VisualStyles渲染。我需要做一些事情,以专门为我的所有者绘制控件启用VisualStyle呈现吗?我试过SetWindowTheme在我的控制,但我不知道什么主题类发送。任何帮助将不胜感激。谢谢!

I have a ComboBox that I have set DrawMode = DrawMode.OwnerDrawFixed. Then I handle the OnDrawItem event and everything works perfectly. However, it looks very different from a standard ComboBox because mine doesn't seem to be rendered using VisualStyles. Do I need to do something to specifically enable VisualStyle rendering for my owner drawn control? I have tried SetWindowTheme on my control, but I'm not sure what theme class to send. Any help would be much appreciated. Thanks!

推荐答案

所有者绘画的缺点是,当你打开它时,一切。你几乎完全是自己的。

The down side of owner-draw is that when you turn it on, the owner (you) has to draw everything. You are almost completely on your own.

如果你想要视觉样式,那么你必须直接调用VisualStyles API来做你想要的。如果你想显示所选,聚焦,启用/禁用状态,那么你必须编写代码来处理它们。

If you want visual styles, then you have to call the VisualStyles APIs directly to do what you want. If you want to show selected, focussed, enabled/disabled states, then you have to write code to deal with them all.

这不是你的组合框问题,但作为如何使用VisualStyles的示例,这里是如何使用VisualStyles在自绘的TreeView绘制加/减号图标:

This isn't a direct answer for your combo-box issues, but as an example of how to use VisualStyles, here is how I've used VisualStyles in an owner-drawn TreeView to draw the Plus/Minus icon:

// 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);
}

这篇关于OwnerDraw ComboBox与VisualStyles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆