VisualStyles颜色不一致

时间:2018-10-16 18:30:55

标签: c# .net winforms

我只是在搞弄.NET使用Winforms提供的视觉样式,所以我遇到了问题。我只是在执行此代码,从自定义面板的OnPaint方法调用,没什么特别的。

private void DrawBox(PaintEventArgs e)
{
        ComboBoxRenderer.DrawDropDownButton(e.Graphics, e.ClipRectangle, ComboBoxState.Normal);}

我的问题是按钮的背景色是灰色,而真正的组合框的背景色是白色(无论如何在我的计算机上)。

这里有两个问题,为什么要更改颜色以及如何使按钮使用与真正的ComboBox相同的背景色?

谢谢 丹尼

1 个答案:

答案 0 :(得分:3)

ClipRectangle不是您想要的。设置要绘制的实际矩形。话虽这么说,是的,使用VisualStyles会让你发疯。这将使您接近:

VisualStyleRenderer vsr = new VisualStyleRenderer("EDIT", 1, 1);
vsr.DrawBackground(e.Graphics, controlRectangle);
vsr.SetParameters("COMBOBOX", 7, 1);
vsr.DrawBackground(e.Graphics, arrowRectangle);
相关问题