vb.net 如何使按钮背景透明?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27628216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make button background transparent?
提问by Hoh
I have created one button and applied image (.png with transparent background) on it.
My button background is set on transparent but as you can see the background color is still there.
How can I make this work as it should?
我创建了一个按钮并在其上应用了图像(具有透明背景的 .png)。
我的按钮背景设置为透明,但如您所见,背景颜色仍然存在。
我怎样才能使这项工作正常进行?
回答by HKImpact
Give this a shot.
试一试。
'Making Existing Button Transparent
btnKasa.FlatStyle = Windows.Forms.FlatStyle.Flat
btnKasa.FlatAppearance.BorderSize = 0
btnKasa.FlatAppearance.MouseDownBackColor = Color.Transparent
btnKasa.FlatAppearance.MouseOverBackColor = Color.Transparent
btnKasa.BackColor = Color.Transparent
回答by Zairja
Another option that I came up with is to call:
我想出的另一个选择是调用:
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
when the form is created (e.g. in the constructor after InitializeComponent()
). The button's BackColor
is set to Transparent, as well (this can be done in code behind or in the properties).
创建表单时(例如,在 之后的构造函数中InitializeComponent()
)。按钮BackColor
也设置为透明(这可以在代码隐藏或属性中完成)。