Pratik Singhal
Pratik Singhal

Reputation: 6492

Why is the form opacity not changing?

I was just experimenting with windows forms and came across the property Opacity. I made a very simple program containing a form with a textbox and added the following code:-

   this.textBox1.MouseHover += ChangeOpacity ; 
   private void ChangeOpacity(object sender, EventArgs e )
   {
      this.Opacity = 50 ; 
      this.Refresh() ; 
   }

I want to change the opacity of the the form to 50% when the user hovers it's mouse over the textbox, but this code is not working. The opacity still remains at 100%. Can anyone point out the mistake I am doing in the above code, or what should I do to correct my problem. I also tried using Invalidate() ans then Update() but it is still not changing the opacity.

Upvotes: 0

Views: 4535

Answers (2)

A.K.
A.K.

Reputation: 3331

Opacity goes in the values from 0 to 1

so 100 % would be a 1 and 50 % would be a .5 and 0% would be a 0.

try with it

this.Opacity=.5;

Upvotes: 2

Vishal Suthar
Vishal Suthar

Reputation: 17194

The Opacity would be in percentage. The default would be 1.00

Try putting:

this.Opacity = 0.5;

Upvotes: 8

Related Questions