Ich hab mal wieder ein kleines Sample zusammengestellt welches die Api-Function AnimateWindow und dessen Verwendung aufzeigt.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace Blender
{
/// <summary>
/// AnimateWindow-Sample by Programmierhans
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
#region Fields
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.Container components = null;
#endregion
#region Constructors / IDisposable / Designer-Code
public Form1()
{
//
// Erforderlich für die Windows Form-Designerunterstützung
//
InitializeComponent();
//
// TODO: Fügen Sie den Konstruktorcode nach dem Aufruf von InitializeComponent hinzu
//
}
/// <summary>
/// Die verwendeten Ressourcen bereinigen.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(528, 446);
this.Name = "Form1";
this.Text = "AnimateWindow-Sample by Programmierhans";
}
#endregion
#endregion
#region Main-EntryPoint
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
#endregion
#region Sample-Code
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
string originalText=this.Text;
int intAnimationSpeed=1000;//Default ist 200;
this.Text="Blending";
//Blending rein / raus
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_BLEND);
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_BLEND);
this.Text="Center";
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_CENTER);
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_CENTER);
this.Text="Slide";
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_SLIDE);
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_SLIDE);
this.Text="Vertikal negativ";
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_VER_NEGATIVE);
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_VER_NEGATIVE);
this.Text="Vertikal positiv";
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_VER_POSITIVE);
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_VER_POSITIVE);
this.Text="Horizontal negativ";
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_HOR_NEGATIVE);
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_HOR_NEGATIVE);
this.Text="Horizontal positiv";
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_HOR_POSITIVE);
AnimateWindow(this,intAnimationSpeed,AnimateWindowStyle.AW_HOR_POSITIVE);
this.Text="Diagonal negativ";
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_NEGATIVE | AnimateWindowStyle.AW_HOR_NEGATIVE);
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_NEGATIVE | AnimateWindowStyle.AW_HOR_NEGATIVE);
this.Text="Diagonal positiv";
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_POSITIVE | AnimateWindowStyle.AW_HOR_POSITIVE);
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_POSITIVE | AnimateWindowStyle.AW_HOR_POSITIVE);
this.Text="Diagonal vertikal negativ horizontal positiv";
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_NEGATIVE | AnimateWindowStyle.AW_HOR_POSITIVE);
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_NEGATIVE | AnimateWindowStyle.AW_HOR_POSITIVE);
this.Text="Diagonal vertikal positive horizontal negativ";
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_POSITIVE | AnimateWindowStyle.AW_HOR_NEGATIVE);
AnimateWindow (this,intAnimationSpeed,AnimateWindowStyle.AW_VER_POSITIVE | AnimateWindowStyle.AW_HOR_NEGATIVE);
this.Text=originalText;
}
#endregion
#region AnimateWindow
/// <summary>
/// Animiert ein Control / Form
/// </summary>
/// <param name="pControl">Das zu animierende Control / Form</param>
/// <param name="dwTimeInMilliSeconds">Zeit in Milliseconds die die Animation dauern soll (Default = 200)</param>
/// <param name="dwFlags">Die Flags wie animiert werden soll</param>
/// <returns></returns>
public static bool AnimateWindow(Control pControl,int dwTimeInMilliSeconds,AnimateWindowStyle dwFlags)
{
//Visible - Flag selber setzen
bool blnNewVisible=!pControl.Visible;
int flags=(int)dwFlags;
flags=pControl.Visible?flags|0x00010000:flags|0x00020000;
//Animation
bool ret=AnimateWindow(pControl.Handle,dwTimeInMilliSeconds,(int)flags)!=0;
//Visible des Controls setzen (wird durch die Animation nicht gesetzt)
pControl.Visible=blnNewVisible;
//Wenn das Control neu sichtbar ist einen Refresh durchführen
if (pControl.Visible)
{
pControl.Refresh();
}
//Return-Value
return ret;
}
/// <summary>
/// Die Api-Function
/// </summary>
/// <param name="hwnd">Handle des zu animierenden Controls / Fensters</param>
/// <param name="dwTime">Zeit in Milliseconds die die Animation dauern soll (Default = 200)</param>
/// <param name="dwFlags">Die Flags wie animiert werden soll</param>
/// <returns></returns>
[DllImport("User32.dll")]
private static extern int AnimateWindow(IntPtr hwnd,int dwTime,int dwFlags);
#endregion
}
/// <summary>
/// Die AnimateWindowStyles (ohne Hide und Activate)
/// </summary>
[Flags]
public enum AnimateWindowStyle
{
AW_HOR_POSITIVE=0x00000001,
AW_HOR_NEGATIVE=0x00000002,
AW_VER_POSITIVE=0x00000004,
AW_VER_NEGATIVE=0x00000008,
AW_CENTER=0x00000010,
AW_SLIDE=0x00040000,
AW_BLEND=0x00080000
}
}
habs getestet - einfach klasse.
gefällt mir recht gut 👍
wofür stehen diese zahlen bzw. befehle: 0x00008?
AW_HOR_POSITIVE=0x00000001,
AW_HOR_NEGATIVE=0x00000002,
AW_VER_POSITIVE=0x00000004,
AW_VER_NEGATIVE=0x00000008,
AW_CENTER=0x00000010,
AW_SLIDE=0x00040000,
AW_BLEND=0x00080000
Original von backdoor
wofür stehen diese zahlen bzw. befehle:
omg hätte auch selber drauf kommen könne. dennoch vielen dank 😁
👍 ja das ist echt nett, habs auch mal ausprobiert...schöne Effekte.
Damit kann man seinem Produkt noch etwas individuelles geben 😉
Schönes Ding !
echt schön! Gefällt mir macht echt was daher. Mal schauen wo man das überall gebrauchen kann 😁
Hallo, geht sowas auch mit modalen Dialogen?
Original von Sprotti
Hallo, geht sowas auch mit modalen Dialogen?
Diese Frage kannst Du selber beantworten.