Opacity of Buttons/TextBoxes - VB.NET

2019-04-08 22:21发布

问题:

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.

回答1:

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.

Your alternative is to use WPF, which allows setting the opacity of controls.



回答2:

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.



回答3:

Just set the Alpha level in your RGBA setting for the color of the control. The code will look something like this:

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.



回答4:

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.



回答5:

<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.



回答6:

I think you can fade a panel if you put a button in one.



回答7:

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:



回答8:

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!!!