简体   繁体   English

为什么表单不透明度没有变化?

[英]Why is the form opacity not changing?

I was just experimenting with windows forms and came across the property Opacity . 我只是在试验Windows窗体,遇到了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. 当用户将鼠标悬停在文本框上时,我想将窗体的不透明度更改为50%,但是此代码不起作用。 The opacity still remains at 100%. 不透明度仍然保持在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. 我也尝试过使用Invalidate()Update()但它仍未更改不透明度。

The Opacity would be in percentage. Opacity将以百分比表示。 The default would be 1.00 默认1.00

Try putting: 尝试放入:

this.Opacity = 0.5;

Opacity goes in the values from 0 to 1 不透明度的取值范围是0到1

so 100 % would be a 1 and 50 % would be a .5 and 0% would be a 0. 因此100%为1,而50%为0.5,0%为0。

try with it 试试看

this.Opacity=.5;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM