按钮周围的浅蓝色边框
问题描述:
在Winforms中,看起来像焦点的按钮有一个浅蓝色边框。
In Winforms, it looks like the button which has focus has a light blue border.
在我的表单中有两个按钮,当表单首次加载时,button1有焦点并有一个浅蓝色边框。
In my form which has two buttons, when the form first loads, button1 has focus and has a light blue border.
点击button2后,它有一个浅蓝色边框。
After I click on button2, it then has a light blue border.
我可以将淡蓝色更改为其他颜色吗?
Can I change the light blue to a different color?
答
我认为没有一个简单的属性(有人可能会纠正我),但你可以使用Paint事件。 / p>
I don't think there's a simple property for that (someone might correct me), but you can use the Paint event.
private void button1_Paint(object sender, PaintEventArgs e)
{
Button b = sender as Button;
if (b.Focused)
{
e.Graphics.DrawRectangle(new Pen(Color.Red), new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1));
}
}