gpt4 book ai didi

c# - VisualStyles 颜色不一致

转载 作者:行者123 更新时间:2023-11-30 21:31:48 24 4
gpt4 key购买 nike

我只是在使用 Winforms 处理 .NET 提供的视觉样式,我遇到了一个问题。我只是执行这段代码,从自定义面板的 OnPaint 方法调用,没有什么特别的。

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

我的问题是按钮的背景颜色是灰色,而真正的 ComboBox 的背景颜色是白色(无论如何在我的电脑上)。

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

谢谢丹尼

最佳答案

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

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

关于c# - VisualStyles 颜色不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52841897/

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