2009-12-17 28 views
6

我有一个组合框,我已经设置DrawMode = DrawMode.OwnerDrawFixed。然后我处理OnDrawItem事件,并且一切正常。但是,它看起来与标准的ComboBox有很大的不同,因为我的VisualStyles似乎不能渲染。我是否需要做一些事情来为我的所有者绘制控件专门启用VisualStyle渲染?我在我的控件上尝试过SetWindowTheme,但我不确定要发送什么主题类。任何帮助将非常感激。谢谢!OwnerDraw与VisualStyles的组合框

回答

6

所有者绘制的缺点是当你打开它时,所有者(你)必须绘制所有东西。你几乎完全靠自己。

如果你想要视觉样式,那么你必须直接调用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); 
} 
+0

我试图使用VisualStyleRenderer绘制的一部分,但我能找到的唯一VisualStyleElement是ComboBox.Button。我会更多地调查这些,或者放弃,让它们都变得没有风格。 :) – 2009-12-17 20:20:31