复选框焦点外观看起来像鼠标悬停

时间:2021-06-29 07:31:14

I'm trying to find out how to make the appearance of a check box look like it does when you hover a mouse over it. I have a group of check boxes without labels and I want to indicate focus this way. I'm currently drawing a focus rectangle around them and it works fine but I'd like to try it this way instead.

我试图找出如何使复选框的外观看起来像将鼠标悬停在它上面时的样子。我有一组没有标签的复选框,我想以这种方式表示焦点。我正在绘制一个围绕它们的焦点矩形,它工作正常,但我想尝试这种方式。

I know I can paint it myself but I figure it's being done already so I'd rather take advantage of that if possible.

我知道我可以自己画画,但我认为它已经完成,所以如果可能的话,我宁愿利用它。

1 个解决方案

#1


You can use either the CheckBoxRenderer (if your application is using visual styles) or ControlPaint.DrawCheckBox (if you are not using visual styles).

您可以使用CheckBoxRenderer(如果您的应用程序使用视觉样式)或ControlPaint.DrawCheckBox(如果您不使用视觉样式)。

If you want to use visual styles, but your end users may have visual styles or not, or if they will ever run the application while connected through remote desktop (which is likely), you will need to check the VisualStyleRenderer.IsSupported static property to determine which method to use; trying to use VisualStyleRenderer (from which CheckBoxRenderer descends) while visual styles are not supported will result in an exception.

如果您想使用视觉样式,但最终用户可能没有视觉样式,或者如果他们在通过远程桌面(很可能)连接时运行应用程序,则需要检查VisualStyleRenderer.IsSupported静态属性确定使用哪种方法;尝试使用VisualStyleRenderer(CheckBoxRenderer从中下降)而不支持视觉样式将导致异常。

#1


You can use either the CheckBoxRenderer (if your application is using visual styles) or ControlPaint.DrawCheckBox (if you are not using visual styles).

您可以使用CheckBoxRenderer(如果您的应用程序使用视觉样式)或ControlPaint.DrawCheckBox(如果您不使用视觉样式)。

If you want to use visual styles, but your end users may have visual styles or not, or if they will ever run the application while connected through remote desktop (which is likely), you will need to check the VisualStyleRenderer.IsSupported static property to determine which method to use; trying to use VisualStyleRenderer (from which CheckBoxRenderer descends) while visual styles are not supported will result in an exception.

如果您想使用视觉样式,但最终用户可能没有视觉样式,或者如果他们在通过远程桌面(很可能)连接时运行应用程序,则需要检查VisualStyleRenderer.IsSupported静态属性确定使用哪种方法;尝试使用VisualStyleRenderer(CheckBoxRenderer从中下降)而不支持视觉样式将导致异常。