如何在 C# 中的按钮上设置/更改/删除焦点样式? [英] How to set/change/remove focus style on a Button in C#?
问题描述
我有几个按钮,我修改了它们的外观.我将它们设置为带有背景和自定义边框的平面按钮,因此它们看起来都很漂亮,不再像普通按钮(实际上,它们现在看起来像 Office 2003 按钮;-).按钮的边框为 1 个像素.
I have a couple of buttons of which I modified how they look. I have set them as flat buttons with a background and a custom border so they look all pretty and nothing like normal buttons anymore (actually, they look like Office 2003 buttons now ;-). The buttons have a border of one pixel.
但是,当按钮被选中(通过单击或键盘操作(如按下 Tab 键)获得焦点)时,按钮突然在其周围获得相同颜色的额外边框,因此使其成为两个像素的边框.此外,当我禁用一像素边框时,按钮不会在焦点上获得一像素边框.
However when the button gets selected (gets the focus through either a click or a keyboard action like pressing the tab key) the button suddenly gets and extra border around it of the same colour, so making it a two pixel border. Moreover when I disable the one pixel border, the button does not get a one pixel border on focus.
在网络上,这个问题的提问很像如何禁用按钮上的焦点",但这不是我想要的:焦点应该仍然存在,只是不显示 就像现在一样.
On the net this question is asked a lot like 'How can I disable focus on a Button', but that's not what I want: the focus should still exist, just not display in the way it does now.
有什么建议吗?:-)
推荐答案
这是您要找的效果吗?
public class NoFocusCueButton : Button
{
protected override bool ShowFocusCues
{
get
{
return false;
}
}
}
您可以像使用普通按钮一样使用这个自定义按钮类,但它不会为您提供额外的焦点矩形.
You can use this custom button class just like a regular button, but it won't give you an extra rectangle on focus.
这篇关于如何在 C# 中的按钮上设置/更改/删除焦点样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!