1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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
}
|