Rubrik: Oberfläche · Effekte | VB-Versionen: VB6 | 20.05.09 |
Ein-/Ausblendeffekt für Fenster Zwei kleine Funktionen zur Realisierung eines Fenster Ein-/Ausblendeffekts. | ||
Autor: Dieter Otter | Bewertung: | Views: 10.660 |
www.tools4vb.de | System: Win9x, WinNT, Win2k, WinXP, Win7, Win8, Win10, Win11 | Beispielprojekt auf CD |
Heute möchten wir Ihnen zwei einfache Funktionen vorstellen, mit denen sich ein Fenster langsam ein- bzw. ausblenden lässt.
Fügen Sie nachfolgenden Code in ein Modul ein:
Option Explicit ' benötigte API-Deklaration Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' Fenster langsam einblenden Public Sub FadeIn(oForm As Form, _ Optional ByVal nStep As Long = 75, _ Optional ByVal maxWidth As Long = 0, _ Optional ByVal maxHeight As Long = 0) Dim w As Long Dim h As Long With oForm If maxWidth = 0 Then maxWidth = .Width If maxHeight = 0 Then maxHeight = .Height ' minimale Fenstergröße .Width = 300 .Height = 300 On Error Resume Next If Not .Visible Then .Visible = True On Error GoTo 0 While .Width < maxWidth And .Height < maxHeight w = .Width + nStep If w > maxWidth Then w = maxWidth h = .Height + nStep If h > maxHeight Then h = maxHeight .Move .Left, .Top, w, h ' kurz warten .Refresh Sleep (5) Wend End With End Sub
' Fenster langsam ausblenden Public Sub FadeOut(oForm As Form, _ Optional ByVal nStep As Long = 75) Dim w As Long Dim h As Long Dim minWidth As Long Dim minHeight As Long With oForm minWidth = 330 minHeight = 330 w = .Width h = .Height On Error Resume Next While w > minWidth And h > minHeight w = w - nStep h = h - nStep .Move .Left, .Top, w, h ' kurz warten .Refresh Sleep (5) Wend On Error GoTo 0 End With End Sub
Aufrufbeispiel:
Private Sub Form_Load() ' Fenster langsam einblenden FadeIn Me End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) ' Form ausblenden FadeOut Me End Sub
Anmerkung von Gerd Kuklau (25.05.09)
Der Ausblendeffekt sieht m.E. schöner aus, wenn man zusätzlich ein DoEvents verwendet.
Dadurch bleibt der Fensterrahmen (Border) nicht sichtbar stehen:
' Fenster langsam ausblenden Public Sub FadeOut(oForm As Form, _ Optional ByVal nStep As Long = 75) Dim w As Long Dim h As Long Dim minWidth As Long Dim minHeight As Long With oForm minWidth = 330 minHeight = 330 w = .Width h = .Height On Error Resume Next While w > minWidth And h > minHeight w = w - nStep h = h - nStep .Move .Left, .Top, w, h ' kurz warten .Refresh ' sieht schöner aus DoEvents Sleep (5) Wend On Error GoTo 0 End With End Sub