按钮/文本框的不透明度 - VB.NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1751914/
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
Opacity of Buttons/TextBoxes - VB.NET
提问by lab12
Is it possible to set the opacity of a button or textbox? I know that you can set the opacity for a form, but I'm not so sure about a button or textbox.
是否可以设置按钮或文本框的不透明度?我知道您可以为表单设置不透明度,但我对按钮或文本框不太确定。
回答by Alex Essilfie
There is no way to set the opacity of any control in WinForms. Only Forms have the opacity property. If you want to make any control appear semi-transparent, you'll have to implement the whole control from scratch and that will most likely involve drawing the control as an image onto its parent.
无法在 WinForms 中设置任何控件的不透明度。只有表单具有不透明度属性。如果要使任何控件显示为半透明,则必须从头开始实现整个控件,这很可能涉及将控件作为图像绘制到其父控件上。
Your alternative is to use WPF, which allows setting the opacity of controls.
您的替代方法是使用 WPF,它允许设置控件的不透明度。
回答by Joe
I think you can fade a panel if you put a button in one.
我认为如果你把一个按钮放在一个面板上,你可以淡化一个面板。
回答by ur_Auror
What I did is to edit my own button (must be an image) on Photoshop, and there, I lower its opacity. So once I put my image on the form (which is my button), it looked like I applied opacity in it. Like this:
我所做的是在 Photoshop 上编辑我自己的按钮(必须是图像),然后在那里降低其不透明度。所以一旦我把我的图像放在表单上(这是我的按钮),看起来我在其中应用了不透明度。像这样:
回答by Sonny Boy
Just set the Alpha level in your RGBA setting for the color of the control. The code will look something like this:
只需在 RGBA 设置中为控件的颜色设置 Alpha 级别。代码将如下所示:
Control.Backcolor = Color.FromArgb(255, 255, 255, 255)
The first value passed into the FromArgb method is the Alpha. A high value will mean high opacity whereas a low value will mean a high transparency. You may need to set the control's Forecolor property as well if you want that to be transparent, too.
传递到 FromArgb 方法的第一个值是 Alpha。高值将意味着高不透明度,而低值将意味着高透明度。如果您也希望控件的 Forecolor 属性也是透明的,则可能还需要设置该属性。
回答by Jeremy Morgan
No, opacity is not a button property, it's inherited from whatever the form is set to. I don't know of any way of doing this short of "faking it" by using an image of a button faded to appear translucent.
不,不透明度不是按钮属性,它是从表单设置的任何内容继承的。我不知道有什么方法可以通过使用褪色以显示半透明的按钮图像来“伪造”。
回答by KasteR
On your form that the control rests on, set TransparencyKey to a color (ex: Fuchsia), then make your control's background color as Fuchsia. You're welcome.
在控件所在的窗体上,将 TransparencyKey 设置为一种颜色(例如:紫红色),然后将控件的背景颜色设为紫红色。别客气。
回答by Ali Mousavi
<asp:ImageButton ID="avbtn" runat="server" Height="55px"
ImageUrl="~/images/avatar.jpg"
onmouseout="this.style.opacity=0.7;this.filters.alpha.opacity=40"
onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"
style="opacity:0.4;filter:alpha(opacity=40)" />
This one works fine for an ImageButton,but I haven't tested it on anything else.
这个适用于 ImageButton,但我还没有在其他任何东西上测试过它。
回答by Titas
Easy way: Select a random colour of the textbox you want to make transparent by going to it's property-backcolor-any. Then come to the source and find the colour code of the colour you have chosen and write transparent and you are done. Ex:
简单的方法:通过转到它的属性背景色任意选择要使其透明的文本框的随机颜色。然后来源,找到你选择的颜色的颜色代码写透明就大功告成了。前任:
<asp:TextBox ID="TextBox1"
runat="server" **BackColor="transparent"** Height="55px" Width="498px"> </asp:Textbox>
Same for VB as well. Cheers!!!
VB 也一样。干杯!!!