Page 1 of 3 123 LastLast
Results 1 to 40 of 115

Thread: Animated Window Effects with "Toast" popup demo

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Animated Window Effects with "Toast" popup demo

    C# version here.

    FormAnimator class - A helper class that you can add an instance of to a form to provide animation when the form is shown, hidden or closed. Supported animations are Roll (form is unrolled and rolled up from one edge to the opposite), Centre (form unrolls from the centre out and rolls up from all edges in), Slide (form slides in and out from one edge to the opposite) and Blend (form fades in and out). Roll and Slide animations can be up, down, left, right or diagonal. To use this class just add a single line of code similar to this to your form:
    VB Code:
    1. Private myAnimator As New FormAnimator(Me, FormAnimator.AnimationMethod.Slide, FormAnimator.AnimationDirection.Up, 400)

    ToastForm class - An inherited Form class that uses the FormAnimator class to produce the same "toast" effect used by MSN Messenger and other apps, where the form slides up from the system tray and then slides back again after a period of time. To use this class just add code like this:
    VB Code:
    1. Dim myToastForm As New ToastForm(5000, "This is a ""toast"" popup demo.")
    2.  
    3. myToastForm.Show()

    Edit: 30/09/2005
    I've updated the ToastForm class so that it now will not receive focus when it is displayed. It will still receive focus if you click on it though.

    Edit: 30/09/2005
    I've updated the ToastForm class so that existing windows will move up the screen to make way for new ones so that they are not covered.

    Edit: 30/09/2005
    I've updated the ToastForm class so that it stacks properly if the Height is changed and/or multiple forms are opened with different lifetimes.

    Try putting the following code in a form and pressing the button several times in succession to see this in action:
    VB Code:
    1. Dim myRandom As New Random
    2.     Dim formNumber As Integer = 1
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         Dim toast As New ToastForm(myRandom.Next(5000, 10000), "This is form number " & Me.formNumber.ToString())
    6.  
    7.         toast.Height = myRandom.Next(150, 300)
    8.         toast.Show()
    9.         Me.formNumber += 1
    10.     End Sub
    Edit: 01/10/2005
    I don't know if it will help, but for those who have been having issues getting this to work I've attached a full project (VS.NET 2003) that was working for me, so hopefully for you too.

    Edit: 07/10/2005
    It appears that the issues that some have been having are due to a bug in the Framework that was fixed in SP1, so apply SP1 for the .NET Framework 1.1 and all should be well.

    Edit: 21-Nov-2005
    I've removed the original attachments and added new ones. The attached solution was rewritten in VB 2005 with a few changes. The attached class file is from that solution if you just want animation without the toast feature.

    Edit: 27-Nov-2008
    Set the TopMost property of the ToastForm class to True to ensure notification windows were not hidden behind other windows if the caller is not currently active.
    Attached Files Attached Files
    Last edited by jmcilhinney; Nov 26th, 2008 at 10:38 PM. Reason: Remove original and replace with better code

  2. #2
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Fading form in and out

    Hey Jm...
    This is really cool...
    But,if u dont mind,please just tell me what this line does "AddHandler m_FadeTimer.Tick, AddressOf FadeForm"
    It adds a timer to the form while closing..and what does AddressOf fadeform mean?

    Thanks in advance

    Godwin

  3. #3

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Fading form in and out

    That line simply attaches the FadeForm method to the Tick event of the Timer object. Normally you would add the Timer to the form in the designer and double-click it to create an event handler automatically. That line has the same effect as having "Handles m_FadeTimer.Tick" at the end of the procedure's declaration. I just used that method so that you could see everthing that was happening, rather than do some things in the designer that you would be unaware of.

  4. #4
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Fading form in and out

    I used to use form1.controls.add(something) ...but,now,i learnt something new
    It works great..Im using this now in my program Thanks

    Godwin

  5. #5

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Fading form in and out

    If you want to add a control to a form you would still need to do that. A Timer is a component, not a control. It doesn't get displayed on the form so it doesn't need to be added to the form's Controls property, and in fact cannot be. Anything that you need to actually display on the form must still be added to it's Controls collection.

  6. #6

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    I have rewritten the code into a helper class that you can use with any existing form without making any changes to the form itself. You might use this helper class something like this:
    VB Code:
    1. Private myForm As New Form
    2.     Private myAnimator As New FormAnimator(myForm, FormAnimator.AnimationTypes.Blend, 300)
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         myForm.Show()
    6.     End Sub
    7.  
    8.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    9.         myForm.Hide()
    10.     End Sub
    and the form will be animated automatically. Here is the code for the FormAnimator helper class:
    VB Code:
    1. 'Animates a form when it is shown, hidden or closed.
    2. Public NotInheritable Class FormAnimator
    3.  
    4.     'The types of animation available.
    5.     Public Enum AnimationTypes
    6.         Roll = &H0      'Roll out from edge to show; Roll in to edge to hide.  Requires direction.  Default animation.
    7.         Centre = &H10   'Expand out from centre to show; Collapse in to centre to hide.
    8.         Slide = &H40000 'Slide out from edge to show; Slide in to edge to hide.  Requires direction.
    9.         Blend = &H80000 'Blend from transaprent to opaque to show; Blend from opaque to transparent to hide.
    10.     End Enum
    11.  
    12.     'The directions in which the Slide animation can be shown.
    13.     'The Flags attribute indicates that directions can be combined.
    14.     <Flags()> Public Enum SlideDirections
    15.         None = 0
    16.         Right = &H1 'Slide from left to right.
    17.         Left = &H2  'Slide from right to left.
    18.         Down = &H4  'Slide from top to bottom.
    19.         Up = &H8    'Slide from bottom to top.
    20.     End Enum
    21.  
    22.     Private Const AW_HIDE As Integer = &H10000      'Hide the form.
    23.     Private Const AW_ACTIVATE As Integer = &H20000  'Activate the form.
    24.  
    25.     Private WithEvents m_Form As Form               'The form to be animated.
    26.  
    27.     Private m_Type As AnimationTypes                'The type of animation used to show and hide the form.
    28.     Private m_Direction As SlideDirections          'The direction in which to Roll or Slide the form.
    29.     Private m_Duration As Integer = 500             'The number of milliseconds over which the animation is played.
    30.  
    31.     'The type of animation used to show and hide the form.
    32.     Public Property AnimationType() As AnimationTypes
    33.         Get
    34.             Return Me.m_Type
    35.         End Get
    36.         Set(ByVal Value As AnimationTypes)
    37.             Me.m_Type = Value
    38.         End Set
    39.     End Property
    40.  
    41.     'The direction in which to Roll or Slide the form.
    42.     Public Property SlideDirection() As SlideDirections
    43.         Get
    44.             Return Me.m_Direction
    45.         End Get
    46.         Set(ByVal Value As SlideDirections)
    47.             Me.m_Direction = Value
    48.         End Set
    49.     End Property
    50.  
    51.     'The number of milliseconds over which the animation is played.
    52.     Public Property AnimationDuration() As Integer
    53.         Get
    54.             Return Me.m_Duration
    55.         End Get
    56.         Set(ByVal Value As Integer)
    57.             Me.m_Duration = Value
    58.         End Set
    59.     End Property
    60.  
    61.     'Windows API function used to animate the form.
    62.     Private Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, _
    63.                                                               ByVal dwtime As Integer, _
    64.                                                               ByVal dwflags As Integer) As Boolean
    65.  
    66.     'Creates a new FormAnimator object for the specified form.
    67.     Public Sub New(ByVal form As Form)
    68.         Me.m_Form = form
    69.     End Sub
    70.  
    71.     'Creates a new FormAnimator object for the specified form using the specified animation type over the specified duration.
    72.     Public Sub New(ByVal form As Form, _
    73.                    ByVal type As AnimationTypes, _
    74.                    ByVal duration As Integer)
    75.         Me.New(form)
    76.  
    77.         Me.m_Type = type
    78.         Me.m_Duration = duration
    79.     End Sub
    80.  
    81.     'Creates a new FormAnimator object for the specified form using the specified animation type in the specified
    82.     'direction over the specified duration.  This is intended to be used with Roll and Slide animations.
    83.     Public Sub New(ByVal form As Form, _
    84.                    ByVal type As AnimationTypes, _
    85.                    ByVal direction As SlideDirections, _
    86.                    ByVal duration As Integer)
    87.         Me.New(form, type, duration)
    88.  
    89.         Me.m_Direction = direction
    90.     End Sub
    91.  
    92.     'Animates the form automatically when it is shown or hidden.
    93.     Private Sub m_Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles m_Form.VisibleChanged
    94.         Dim flags As Integer = Me.m_Type Or Me.m_Direction
    95.  
    96.         If Me.m_Form.Visible Then
    97.             'Activate the form.
    98.             flags = flags Or Me.AW_ACTIVATE
    99.         Else
    100.             'Hide the form.
    101.             flags = flags Or Me.AW_HIDE
    102.         End If
    103.  
    104.         Me.AnimateWindow(Me.m_Form.Handle, _
    105.                          Me.m_Duration, _
    106.                          flags)
    107.     End Sub
    108.  
    109.     'Animates the form automatically when it closes.
    110.     Private Sub m_Form_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles m_Form.Closing
    111.         'Hide the form.
    112.         Me.AnimateWindow(Me.m_Form.Handle, _
    113.                          Me.m_Duration, _
    114.                          Me.AW_HIDE Or Me.m_Type Or Me.m_Direction)
    115.     End Sub
    116.  
    117. End Class

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Animated Window Effects, AKA Fading form in and out

    This duplicates the Windows Forms animations, bu thow could you do a dual direction animation? Down + Right, etc?

    Very nice code btw.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    I apologise to the author if this duplicates someone else's work. To set a direction like down and right you use a bitwise Or for the SlideDirection property, e.g.
    VB Code:
    1. myAnimator.SlideDirection = FormAnimator.SlideDirections.Down Or FormAnimator.SlideDirections.Right

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Animated Window Effects, AKA Fading form in and out

    Ok, so its possible to 'Or' them to gether. Will this replicate the animated minimizing like MSN?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    I've not used MSN Messenger so I don't know exactly what that looks like, but if you mean like shrinking towards its icon on the TaskBar then no, it won't. That functionality is not included in the AnimateWindow API.

  11. #11
    Lively Member FYRe's Avatar
    Join Date
    Aug 2005
    Location
    Singapore
    Posts
    102

    Re: Animated Window Effects, AKA Fading form in and out

    Quote Originally Posted by jmcilhinney
    I have now removed my original code altogether and replaced it with some that uses the AnimateWindow API, which will fade a form in and out as well as use several other effects. This code can be added to a form itself or it could be adapted to be used in a helper class.
    VB Code:
    1. Public Class AnimatedForm
    2.     Inherits System.Windows.Forms.Form
    3.  
    4.     Public Enum AnimationTypes
    5.         None = 0
    6.         Centre = &H10   'Show outwards from centre out or hide inwards from edge.
    7.         Slide = &H40000 'Slide in or out in the specified direction.
    8.         Blend = &H80000 'Fade in or out.
    9.     End Enum
    10.  
    11.     'The Flags attribute allows horizontal and vertical directions to be combined.
    12.     <Flags()> Public Enum SlideDirections
    13.         None = 0
    14.         Right = &H1 'Slide from left to right.
    15.         Left = &H2  'Slide from right to left.
    16.         Down = &H4  'Slide from top to bottom.
    17.         Up = &H8    'Slide from bottom to top.
    18.     End Enum
    19.  
    20.     Private Const AW_HIDE As Integer = &H10000
    21.  
    22.     Private m_AnimationType As AnimationTypes = AnimationTypes.None     'The type of animation used to show and hide the window.
    23.     Private m_SlideDirection As SlideDirections = SlideDirections.None  'The direction in which to slide the window if the animation type is Slide.
    24.     Private m_AnimationDuration As Integer = 500                        'The number of milliseconds over which the animation is played.
    25.  
    26.     'The type of animation used to show and hide the window.
    27.     Public Property AnimationType() As AnimationTypes
    28.         Get
    29.             Return Me.m_AnimationType
    30.         End Get
    31.         Set(ByVal Value As AnimationTypes)
    32.             Me.m_AnimationType = Value
    33.         End Set
    34.     End Property
    35.  
    36.     'The direction in which to slide the window if the animation type is Slide.
    37.     Public Property SlideDirection() As SlideDirections
    38.         Get
    39.             Return Me.m_SlideDirection
    40.         End Get
    41.         Set(ByVal Value As SlideDirections)
    42.             Me.m_SlideDirection = Value
    43.         End Set
    44.     End Property
    45.  
    46.     'The number of milliseconds over which the animation is played.
    47.     Public Property AnimationDuration() As Integer
    48.         Get
    49.             Return Me.m_AnimationDuration
    50.         End Get
    51.         Set(ByVal Value As Integer)
    52.             Me.m_AnimationDuration = Value
    53.         End Set
    54.     End Property
    55.  
    56.     Private Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, _
    57.                                                               ByVal dwtime As Integer, _
    58.                                                               ByVal dwflags As Integer) As Boolean
    59.  
    60.     Protected Overrides Sub OnLoad(ByVal e As EventArgs)
    61.         Me.AnimateWindow(Me.Handle, _
    62.                          Me.AnimationDuration, _
    63.                          Me.m_AnimationType Or Me.m_SlideDirection)
    64.     End Sub
    65.  
    66.     Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
    67.         Me.AnimateWindow(Me.Handle, _
    68.                          Me.AnimationDuration, _
    69.                          AW_HIDE Or Me.m_AnimationType Or Me.m_SlideDirection)
    70.     End Sub
    71.  
    72. End Class
    Hi JM,

    I copied the whole code as given, however, it doesn't seem to work. Could you maybe attach a copy of the program? preferably ZIP it first before attaching it. I've read the comments and replies. The program seems interesting....

    thks,
    FYRe
    sOMEONE'S gONNA dO iT, wHY nOT yOU ?

  12. #12

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    Quote Originally Posted by FYRe
    Hi JM,

    I copied the whole code as given, however, it doesn't seem to work. Could you maybe attach a copy of the program? preferably ZIP it first before attaching it. I've read the comments and replies. The program seems interesting....

    thks,
    FYRe
    You won't be able to just copy that code and use it as is. I would suggest the best course of action would be to use the helper class from post #6. That is a self-contained class and you will just be able to copy and paste. If you want to use the code that you have quoted in a particular form of your own, you should create your own form first as you normally would and then copy and paste just the contents of my AnimatedForm class into your own form. Like I said, I think the helper class is the better option, though, because it means you don't have to change any code in your form or inherit from a different class than you normally would. If this advice is not satisfactory then by all means post back and I'll post a project, but I think either of the methods I described should get you home.

  13. #13
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Animated Window Effects, AKA Fading form in and out

    that's great jmcilhinney

    nice work

  14. #14
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Animated Window Effects, AKA Fading form in and out

    sorry jmcilhinney, but i need to know why doesn't work on the mdiChild forms,

    it works great on normal forms.

    but it doesn't work on :

    1 - forms with the windowstate = maximized

    2 - forms that is mdi child for a mdiparent

    3 - forms that are showed using : .showdialog method

    is there any possible solutions, as most of the applications i work on is MDI/PArent-Child Form applications. and i liked the fade effect very much.

    i would like also your permession to use this effect in my application

    thx for your kind attention

    rgds

  15. #15

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    I've posted this code here for all to use freely. As for those issues, I must admit that I haven't tested this too much, and not at all outside of regular vanilla forms. I'll have a dig around and see what I can come up with.

  16. #16
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Animated Window Effects, AKA Fading form in and out

    i will wait for your feed back

    thx & RGDS

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Animated Window Effects, AKA Fading form in and out

    I wouldnt think that it would be a good idea to animate mdi child forms. Probably better to just animate the mdi parent.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Animated Window Effects, AKA Fading form in and out

    I wouldnt think that it would be a good idea to animate mdi child forms
    and y is that? is there any technical reasons

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    Re: Animated Window Effects, AKA Fading form in and out

    No, just from a professional program functionality standpoint. I cant recall ever seeing a mdi app that had the child forms animated. Usually they are always maximized so not much need is all.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    Quote Originally Posted by maged
    sorry jmcilhinney, but i need to know why doesn't work on the mdiChild forms,

    it works great on normal forms.

    but it doesn't work on :

    1 - forms with the windowstate = maximized

    2 - forms that is mdi child for a mdiparent

    3 - forms that are showed using : .showdialog method

    is there any possible solutions, as most of the applications i work on is MDI/PArent-Child Form applications. and i liked the fade effect very much.

    i would like also your permession to use this effect in my application

    thx for your kind attention

    rgds
    My testing and research has yielded the following information.

    1. The supplied code works correctly for Maximized forms when hiding or closing but has no effect when displaying.
    2. The supplied code has no effect when displaying an MDI child form and behaves strangely when hiding or closing an MDI child form.
    3. The supplied code works correctly for forms displayed using ShowDialog.

    I will look into these issues further in the near future. I may be able to incorporate my old code that used a Timer and Opacity to reproduce the Blend effect at least for MDI child and Maximized forms.

    Also note that the call to AnimateWindow in the FormAnimator class is synchronous, so the app's UI will not be updated in other areas during the animation. This means that if a form is placed over another form and then animated, the rear form will not be refreshed until the animation completes. This can lead to some ugly visual effects. I will look at using multi-threading to overcome this issue.

    Stay tuned for future bulletins.

  21. #21

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    I have revised my code a little, so post #6 has been updated with the new version of the FormAnimator class. I have also done a little more research and here are my findings.

    MDI child forms do not support transparency at all. Setting the Opacity of an MDI child form has no effect either. This means that a call to AnimateWindow for an MDI child form using the Blend animation method will always fail.

    Regular Forms:
    The code provided works correctly in all cases.

    Modal Dialogues (displayed using ShowDialog):
    The code provided works correctly in all cases.

    Maximized Forms:
    The code provided has no effect when displaying a form, but works correctly for all animation types when hiding or closing a form. One point to note is that the Blend effect is not so visually appealing when hiding or closing a Maximized form as for a Normal form.

    MDI Child Forms:
    The code provided has no effect when displaying a form. When hiding, the form will be hidden, reshown and then hidden again. When closing, the code provided works correctly for all but the Blend effect.

    In short, you cannot successfully use the Blend effect for MDI child forms at all. I will try to find a solution to the other issues but I cannot guarantee it will be soon, as I have been neglecting my real work too much already. I'll get back to you.

  22. #22

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    OK, I have updated the code again and attached it to this post. I have changed the nomenclature a little and improved support for MDI child forms. It looks like MDI child forms don't support transparency at all so the Blend method is out completely. I've managed to get them to animate properly when they are first shown and when they close. The VisibleChanged event is raised differently for MDI children than for regular forms, so I've excluded support for animating child windows when showing them, other than the first time, and when hiding them. How often do you set the Visible property of an MDI child form to False anyway.

    Edit:
    Attachment removed. See first post.

  23. #23
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Animated Window Effects, AKA Fading form in and out

    that is a great piece of work, thank you

    mt only problem now is :
    [
    everytime i think myself good in vb.net, someone in this forums proves me wrong
    ]
    joking:

    again thank you for the great additions, i will stay tuned for the coming modifications

    rgds

  24. #24
    Member
    Join Date
    Sep 2005
    Posts
    49

    Re: Animated Window Effects, AKA Fading form in and out

    How about mdiparents?

  25. #25

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    Quote Originally Posted by wrecklesswun
    How about mdiparents?
    What about them?

  26. #26

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    "Toast" demo added

    I've rewritten the first post and attached the final code there. I've also attached a demo class that creates a "toast" popup.

  27. #27

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects, AKA Fading form in and out

    I've updated the ToastForm class so that it now will not receive focus when it is displayed. It will still receive focus if you click on it though.

  28. #28

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects with "Toast" popup demo

    I've updated the ToastForm class so that existing windows will move up the screen to make way for new ones so that they are not covered.

  29. #29

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects with "Toast" popup demo

    I've updated the ToastForm class so that it stacks properly if the Height is changed and/or multiple forms are opened with different lifetimes.

  30. #30
    Addicted Member
    Join Date
    Feb 2003
    Posts
    183

    Re: Animated Window Effects with "Toast" popup demo

    Hi, I am having a problem running this. When I click the button I get an error saying

    An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

    Additional Information: hdc
    in m_Form_Load of FormAnimator.

    Any idea why, or I have I made a noob mistake? could you post a solution file in case it's something I have missed?

    Cheers.
    Look into the heart of infinity and find your truth

    Colonel Tom Edwards: This is the most fantastic story I've ever heard
    Jeff Trent: And every word of it's true, too
    Colonel Tom Edwards: That's the fantastic part of it

    ROFL

  31. #31

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects with "Toast" popup demo

    Quote Originally Posted by jud9r
    Hi, I am having a problem running this. When I click the button I get an error saying



    in m_Form_Load of FormAnimator.

    Any idea why, or I have I made a noob mistake? could you post a solution file in case it's something I have missed?

    Cheers.
    Someone else said they had the same issue, but I'm not sure what the problem is. To test it out I downloaded the files I posted, created a new project, added the downloaded files as Existing Items and everything worked fine. I can't really give you any clues I'm afraid except to try to track down exactly which line throws the exception and get an error message and a stack trace.

  32. #32

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects with "Toast" popup demo

    I don't know if it will help, but for those who have been having issues getting this to work I've attached a full project (VS.NET 2003) that was working for me, so hopefully for you too. See post #1.

  33. #33
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Animated Window Effects with "Toast" popup demo

    I encountered this error...

    I'll check out the project you attached...
    Attached Images Attached Images  
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  34. #34

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects with "Toast" popup demo

    Quote Originally Posted by dee-u
    I encountered this error
    You're the third person to say that, but I've not had any issues and it seems that some others haven't either. Could you perhaps put that If block in a Try...Catch block like this:
    VB Code:
    1. Try
    2.     'code here.
    3. Catch ex As Exception
    4.     MessageBox.Show(ex.ToString())
    5. End Try
    By calling ToString on the exception you get much more information, including the call stack.

  35. #35
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Animated Window Effects with "Toast" popup demo

    I tried the project you posted and I also encounter the same error? I'll try putting an error handler in it and post the error...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  36. #36
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Animated Window Effects with "Toast" popup demo

    Here is the error:

    Message: hdc
    Source: System.Windows.Form

    Error:
    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.ArgumentException: hdc
    at System.Windows.Forms.DibGraphicsBufferManager.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
    at System.Windows.Forms.DibGraphicsBufferManager.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
    at System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetBounds)
    at System.Windows.Forms.DibGraphicsBufferManager.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetBounds)
    at System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(IntPtr target, Rectangle targetBounds)
    at System.Windows.Forms.Control.WmPaint(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.Label.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.Label.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
    at System.Windows.Forms.Control.DefWndProc(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.Label.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
    at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
    at System.Windows.Forms.Control.DefWndProc(Message& m)
    at System.Windows.Forms.Form.DefWndProc(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at WindowsApplication2.FormAnimator.AnimateWindow(IntPtr hWnd, Int32 dwTime, Int32 dwFlags)
    at WindowsApplication2.FormAnimator.m_Form_Closing(Object sender, CancelEventArgs e) in E:\VBForumsFiles\FormAnimationAndToastDemo\WindowsApplication2\FormAnimator.vb:line 322
    at System.ComponentModel.CancelEventHandler.Invoke(Object sender, CancelEventArgs e)
    at System.Windows.Forms.Form.OnClosing(CancelEventArgs e)
    at System.Windows.Forms.Form.WmClose(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam)
    at System.Windows.Forms.Control.SendMessage(Int32 msg, Int32 wparam, Int32 lparam)
    at System.Windows.Forms.Form.Close()
    at WindowsApplication2.ToastForm.lifeTimer_Tick(Object sender, EventArgs e) in E:\VBForumsFiles\FormAnimationAndToastDemo\WindowsApplication2\ToastForm.vb:line 229
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)


    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
    ----------------------------------------
    WindowsApplication2
    Assembly Version: 1.0.2103.12260
    Win32 Version: 1.0.2103.12260
    CodeBase: file:///E:/VBForumsFiles/FormAnimationAndToastDemo/WindowsApplication2/bin/WindowsApplication2.exe
    ----------------------------------------
    System.Windows.Forms
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
    ----------------------------------------
    System
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
    ----------------------------------------
    System.Drawing
    Assembly Version: 1.0.5000.0
    Win32 Version: 1.1.4322.573
    CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
    ----------------------------------------
    Microsoft.VisualBasic
    Assembly Version: 7.0.5000.0
    Win32 Version: 7.10.3052.4
    CodeBase: file:///c:/windows/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just in time (JIT) debugging, the config file for this
    application or machine (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
    <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the machine
    rather than being handled by this dialog.

    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  37. #37

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects with "Toast" popup demo

    Man, that exception is thrown so deep in the Framework that I'm not willing to even try to debug it, particularly given the fact that only some people seem to be getting that error. I'm going to say that I have no idea what the problem is and leave it at that. Sorry. I guess the alternative to using APIs is to just use a Timer to animate the form.

  38. #38
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Animated Window Effects with "Toast" popup demo

    Perhaps you have something in your computer that we don't have?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  39. #39

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Animated Window Effects with "Toast" popup demo

    There's obviously some difference, but it's just making an API call so that should be the same on every WinXP machine I would have thought.

  40. #40
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: Animated Window Effects with "Toast" popup demo

    I have XP Pro with SP1, 1.1 FW, .Net 2003
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width