C#的WinForms - 自定义按钮不必要的边界时,未选中的形式 [英] C# WinForms - custom button unwanted border when form unselected

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

问题描述

我在与我在C#中创建一个自定义按钮的问题赢得形式..当选择的形式,但只要我点击从边境出现在按钮的形式远按钮会出现罚款。当这种情况发生的一个很好的例子是在点击桌面,但形式仍然是最大,所以你可以看到它的内容时。问题的一个图象在下面可以看到:

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 不支持 Col​​or.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天全站免登陆