Window shape transparency .. How to control?

I have one window application window now I want to change the form opacity when the application starts. So when the application starts it, the low opacity form will be displayed, and as increse time it will show the full form with 100 opacity . So how to do it. (should I use a timer to control opacity, if so, how ????)

+4
source share
4 answers

in the form constructor you can write something like this.

 this.Opacity = .1; timer.Interval = new TimeSpan(0, 0, intervalinminutes); timer.Tick += ChangeOpacity; timer.Start(); 

And then define a method like this

 void ChangeOpacity(object sender, EventArgs e) { this.Opacity += .10; //replace.10 with whatever you want if(this.Opacity == 1) timer.Stop(); } 
+4
source

To fade out forms in and out, I usually do this:

 for(double opacity = 0.0; opacity <= 1.0; opacity += 0.2) { DateTime start = DateTime.Now; this.Opacity = opacity; while(DateTime.Now.Subtract(start).TotalMilliseconds <= 30.0) { Application.DoEvents(); } } 

This is a nice, easy solution if you do it very rarely. Otherwise, I would recommend using streams.

+3
source

In the constructor, start the timer, which will call the method at each tick.

 timer.Interval = 1000; timer.Tick += new EventHandler(TimerEventProcessor); timer.Start(); 

............

  private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs) { if(this.Opacity < 1) this.Opacity += .1; else timer.Stop(); } 
+1
source

In the constructor, set the opacity to 0 and start the timer with an interval of about 10 or 100 milliseconds. In the timer_Tick event timer_Tick you just need to fire this.Opacity += 0.01;

This will make the opacity start from 0 and increase by 0.01 every few milliseconds to 1 (the opacity is double when it reaches 1, it is completely opaque)

0
source

Source: https://habr.com/ru/post/1388555/


All Articles