Gå til innhold

"Fading" av vindu [LØST]


Anbefalte innlegg

Jeg har følgende kode:

protected override void OnDeactivate(EventArgs e)
{
 base.OnDeactivate(e);
 for (double d = 0.5; d > 0.0; d -= 0.1)
 {
   Opacity = d;
   System.Threading.Thread.Sleep(100);
 }
 Visible = false;
 Opacity = 1.0;
}

for å fade ut programmet OnDeactivate. Men denne gjør bare at jeg får en Grå firkant, som fader ut. Jeg vil at man skal se hele vinduet fade ut. Hvordan får man til dette?

Endret av Manfred
Lenke til kommentar
Videoannonse
Annonse

Løsningen er å legge til denne klassen:

Klikk for å se/fjerne innholdet nedenfor

using System;
using System.Runtime.InteropServices;

namespace MyNameSpace
{
/// <summary>
/// Win32 implementation to show / hide a window with animation.
/// </summary>

public class WinAPI
{
 /// <summary>
 /// Animates the window from left to right. This flag can be used with roll or slide animation.
 /// </summary>
 public const int AW_HOR_POSITIVE = 0X1;
 /// <summary>
 /// Animates the window from right to left. This flag can be used with roll or slide animation.
 /// </summary>
 public const int AW_HOR_NEGATIVE = 0X2;
 /// <summary>
 /// Animates the window from top to bottom. This flag can be used with roll or slide animation.
 /// </summary>
 public const int AW_VER_POSITIVE = 0X4;
 /// <summary>
 /// Animates the window from bottom to top. This flag can be used with roll or slide animation.
 /// </summary>
 public const int AW_VER_NEGATIVE = 0X8;
 /// <summary>
 /// Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
 /// </summary>
 public const int AW_CENTER = 0X10;
 /// <summary>
 /// Hides the window. By default, the window is shown.
 /// </summary>
 public const int AW_HIDE = 0X10000;
 /// <summary>
 /// Activates the window.
 /// </summary>
 public const int AW_ACTIVATE = 0X20000;
 /// <summary>
 /// Uses slide animation. By default, roll animation is used.
 /// </summary>
 public const int AW_SLIDE = 0X40000; 
 /// <summary>
 /// Uses a fade effect. This flag can be used only if hwnd is a top-level window.
 /// </summary>
 public const int AW_BLEND = 0X80000;

 /// <summary>
 /// Animates a window.
 /// </summary>
 [DllImport("user32.dll", CharSet=CharSet.Auto)]
 public static  extern int AnimateWindow (IntPtr hwand , int dwTime , int dwFlags);  
} 
}

Og så bruker jeg denne koden:

WinAPI.AnimateWindow(this.Handle, 1000, WinAPI.AW_HIDE | WinAPI.AW_BLEND);

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
×
×
  • Opprett ny...