vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Blitzschnelles Erstellen von grafischen Diagrammen!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück
Rubrik: Oberfläche · Fenster   |   VB-Versionen: VB2005, VB2008, VB201020.03.12
Fenster animieren

Eine Klasse und ihre Anwendung für das Animieren von Fenstern beim öffnen und schließen.

Autor:   Dietrich HerrmannBewertung:     [ Jetzt bewerten ]Views:  9.584 
ohne HomepageSystem:  WinXP, Win7, Win8, Win10, Win11 Beispielprojekt auf CD 

Auf MSDN findet man die Beschreibung der Animationsmöglichkeiten von Fenstern. Die folgende Klasse stellt diese Möglichkeiten ins VB-Umfeld so zu sagen.

Imports System.Windows.Forms
Imports System.Drawing, System.Runtime.InteropServices
Imports System.Security, System.Security.Permissions
 
Namespace AnimatedWindow
  Friend NotInheritable Class AnimationMethods
 
    Private Const AW_ACTIVATE = &H20000
    Private Const AW_BLEND = &H80000
    Private Const AW_CENTER = &H10
    Private Const AW_SLIDE = &H40000
    Private Const AW_HIDE = &H10000
    Private Const AW_HOR_POSITIVE = &H1
    Private Const AW_HOR_NEGATIVE = &H2
    Private Const AW_VER_POSITIVE = &H4
    Private Const AW_VER_NEGATIVE = &H8
    Private Const WM_PAINT = &HF
 
    <Flags()> _
    Public Enum AnimationFlags As Integer
      ' Activates the window.
      Activate = AW_ACTIVATE
      ' Uses a fade effect. This flag can be used 
      ' only with a top-level window.
      Blend = AW_BLEND
      ' Makes the window appear to collapse inward if Hide 
      ' is used or expand outward if the Hide is not used.
      Center = AW_CENTER
      ' Hides the window. By default, the window is shown.
      Hide = AW_HIDE
      ' Animates the window from left to right. This flag 
      ' can be used with roll or slide animation.
      HorizontalPositive = AW_HOR_POSITIVE
      ' Animates the window from right to left. This flag 
      ' can be used with roll or slide animation.
      HorizontalNegative = AW_HOR_NEGATIVE
      ' Uses a slide animation. By default, roll animation is used.
      Slide = AW_SLIDE
      ' Uses a roll animation.
      Roll = &H0
      ' Animates the window from top to bottom. This flag 
      ' can be used with roll or slide animation.
      VerticalPositive = AW_VER_POSITIVE
      ' Animates the window from bottom to top. This flag 
      ' can be used with roll or slide animation.
      VerticalNegative = AW_VER_NEGATIVE
    End Enum
 
    <SuppressUnmanagedCodeSecurity()> _
    <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    Private Shared Function AnimateWindow(ByVal windowHandle As HandleRef, _
      ByVal time As Integer, ByVal flags As AnimationFlags) As Integer
    End Function
 
    Friend Shared Sub AnimateWindow(ByVal control As Control, _
      ByVal time As Integer, ByVal flags As AnimationFlags)
      Try
        Dim sp As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
        sp.Demand()
        AnimateWindow(New HandleRef(control, control.Handle), time, flags)
      Catch generatedExceptionName As SecurityException
      End Try
    End Sub
  End Class
End Namespace

Am besten wendet man die Animation im VisibleChanged-Ereignis der Form an.

Private Sub myForm_VisibleChanged(ByVal sender As Object, _
  ByVal e As System.EventArgs) Handles Me.VisibleChanged
 
  If Me.Visible Then
    AnimatedWindow.AnimationMethods.AnimateWindow(Me, 200, _
      AnimatedWindow.AnimationMethods.AnimationFlags.Activate Or _
      AnimatedWindow.AnimationMethods.AnimationFlags.VerticalPositive Or _
      AnimatedWindow.AnimationMethods.AnimationFlags.HorizontalPositive)
  Else
    AnimatedWindow.AnimationMethods.AnimateWindow(Me, 200, _
      AnimatedWindow.AnimationMethods.AnimationFlags.Hide Or _
      AnimatedWindow.AnimationMethods.AnimationFlags.VerticalNegative Or _
      AnimatedWindow.AnimationMethods.AnimationFlags.HorizontalNegative)
  End If
End Sub

Die Form wird in diesem Falle bei 'myForm.Show' von links-oben nach rechts-unten aufgemacht und beim Schließen von rechts-unten nach links-oben ausgeblendet.
Die Flags können also auch kombiniert werden; die Temposteuerung erfolgt über 'time' bspw. mit 200 ms.

Dieser Tipp wurde bereits 9.584 mal aufgerufen.

Voriger Tipp   |   Zufälliger Tipp   |   Nächster Tipp

Über diesen Tipp im Forum diskutieren
Haben Sie Fragen oder Anregungen zu diesem Tipp, können Sie gerne mit anderen darüber in unserem Forum diskutieren.

Neue Diskussion eröffnen

nach obenzurück


Anzeige

Kauftipp Unser Dauerbrenner!Diesen und auch alle anderen Tipps & Tricks finden Sie auch auf unserer aktuellen vb@rchiv  Vol.6
(einschl. Beispielprojekt!)

Ein absolutes Muss - Geballtes Wissen aus mehr als 8 Jahren vb@rchiv!
- nahezu alle Tipps & Tricks und Workshops mit Beispielprojekten
- Symbol-Galerie mit mehr als 3.200 Icons im modernen Look
Weitere Infos - 4 Entwickler-Vollversionen (u.a. sevFTP für .NET), Online-Update-Funktion u.v.m.
 
   

Druckansicht Druckansicht Copyright ©2000-2024 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel