Für Fenster die animiert geöffnet werden sollen (z.B. mit einen Einblendeffekt animiert ) stellt die Windows Api eine recht nette Funktion namens AnimateWindow zur Verfügung. Es kann zwischen verschiedenen Effekten gewählt werden:
- AW_BLEND öffnet ein Fenster mit Einblendeffekt
- AW_CENTER rollt das Fenster von der Mitte aus ein
- AW_HOR_xxx und AW_VER_xx rollt die Fenster seitlich oder vertikal ein.
GFU-Schulungen [Anzeige]
VB.NET 2017/2015/2013 EinführungDas Seminar befähigt Sie zur eigenständigen Entwicklung von anwenderorientierten Programmen in VB.NET, worin auch der Einsatz von Datenbanken enthalten ist.
ASP.NET 2.0 und 3.5Dieser Kurs vermittelt Ihnen alle Erweiterungen von Microsoft ASP.NET 2.0. Zu diesen zählen u. a. Data Bindung, Master Pages, und Security.
using System.Runtime.InteropServices
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Button Button1 = new Button();
Controls.Add(Button1);
Button1.Location = new Point((Width - Button1.Width) / 2, Height - 80);
Button1.Text = "Schließen";
Button1.Click += new EventHandler(Button1_Click);
}
public new void Show()
{
AnimateWindow(this.Handle, 500, AW_BLEND | AW_ACTIVATE );
// Wichtig, sonst sieht man nur ein leeres Fenster...
Visible = true;
}
public new void Close()
{
if (IsDisposed == false)
{
AnimateWindow(this.Handle, 400, AW_HIDE | AW_BLEND);
base.Close();
}
}
void Button1_Click(object sender, EventArgs e)
{
Close();
}
[STAThread]
static void Main()
{
Form1 f = new Form1();
// Wichtig: Application.Run benutzt eine anderen Mechanismus, daher muss es schon vorher angezeigt werden
f.Show();
Application.Run(f);
}
#region Win32
const int AW_HIDE = 0X10000;
const int AW_ACTIVATE = 0X20000;
const int AW_SLIDE = 0X40000;
const int AW_BLEND = 0X80000;
const int AW_HOR_POSITIVE = 0X1;
const int AW_HOR_NEGATIVE = 0X2;
const int AW_VER_POSITIVE = 0x4;
const int AW_VER_NEGATIVE = 0x8;
const int AW_CENTER = 0x10;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int AnimateWindow(IntPtr hwand, int dwTime, int dwFlags);
#endregion
}
16 Kommentare zum Snippet