C# WinForms - 未选择表单时自定义按钮不需要的边框 [英] C# WinForms - custom button unwanted border when form unselected

查看:22
本文介绍了C# WinForms - 未选择表单时自定义按钮不需要的边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#win表单中创建了一个自定义按钮的问题..选择表单时,按钮似乎很好,但只要我从远离"按钮上显示边框".发生这种情况的一个很好的例子是单击桌面但表单仍然最大化以便您可以看到其内容.问题的图像如下所示:

I'm having a problem with a custom button I have created in c# win forms.. The button appears fine when the form is selected but as soon as I click away from the form a border appears on the button. A good example of when this happens is when the desktop is clicked but the form is still maximised so you can see its contents. An image of the problem can be seen below:

这不会发生在所有按钮上,只有在之前单击过该按钮时才会发生(一次只出现在一个按钮上).这让我相信这与按钮焦点提示有关,但这些提示设置为 false.边框设置为 0,我也将制表位设置为 false.

This does not happen on all buttons, only when the button has been clicked prior (only appears on one button at a time). This lead me to believe that it was something to do with the button focus cues but these are set to false. The border is set to 0 and I also have tabstop set to false.

有什么建议吗?

推荐答案

当您处理自定义按钮时,您应该设置:

When you're dealing with a custom button you should set:

button.TabStop = false;
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;

然后由于 ButtonBase 不支持 Color.Transparent 上的边框颜色,您可以通过设置 Argb 颜色来解决这个问题:

Then since ButtonBase doesn't support the border color on Color.Transparent, you can overcome the issue by setting an Argb color:

button.FlatAppearance.BorderColor = Color.FromArgb(0, 255, 255, 255); //transparent

这篇关于C# WinForms - 未选择表单时自定义按钮不需要的边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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