如何绘制具有非标准BackColor的按钮? [英] How do I draw a button with a nonstandard BackColor?

查看:53
本文介绍了如何绘制具有非标准BackColor的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ButtonRenderer 在自定义单元格中绘制按钮.我希望按钮具有非标准的BackColor.普通按钮支持此功能,但按钮单元格或 ButtonRenderer 中没有任何内容可支持它.如何绘制具有非标准BackColor的按钮?该方法必须考虑用户的主题-我不能只画自己的按钮.

I'm using a ButtonRenderer to draw a button in a custom cell. I'd like the button to have a nonstandard BackColor. This is supported by normal buttons, but there's nothing in button cells or ButtonRenderer to support it. How do I draw a button with a nonstandard BackColor? The method has to take the user's theme into account - I can't just draw my own button.

推荐答案

ButtonRenderer使用VisualStyleRenderer.DrawBackground()绘制按钮背景.该方法非常了解用户选择的主题,按钮的背景将使用主题指定的颜色.使用非标准的BackColor会违反用户选择的主题.您不能同时拥有这两种方式.

ButtonRenderer uses VisualStyleRenderer.DrawBackground() to draw the button background. That method is very much aware of the user selected theme, the button's background will use the colors specified by the theme. Using a non-standard BackColor would violate the user selected theme. You can't have it both ways.

Button类实际上并不使用ButtonRenderer,它使用从System.Windows.Forms.ButtonInternal命名空间中的内部ButtonBaseAdapter类派生的三个渲染器之一.这些渲染器是内部的,您不能在自己的代码中使用它们.用Reflector或参考源看一下它们,看看需要什么.专注于PaintButtonBackground方法.

The Button class doesn't actually use ButtonRenderer, it uses one of three renderers derived from the internal ButtonBaseAdapter class in the System.Windows.Forms.ButtonInternal namespace. These renderers are internal, you can't use them in your own code. Take a look at them with Reflector or the Reference Source to see what it takes. Focus on the PaintButtonBackground method.

这篇关于如何绘制具有非标准BackColor的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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