#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Sheffield, UK
    Posts
    94
    Rep Power
    12

    Fading forms into and out of sight


    Hi guys

    I've been working on the 'bells and whistles' of my project, and im trying to get my main form to fade into and out of sight, on a click on the icon which sits in the system tray.

    I've set a timer (FaderTimer) to tick ever 100 miliseconds.

    The code is as follows:
    Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
    FaderTimer.Enabled = True
    End Sub

    Private Sub FaderTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FaderTimer.Tick
    If Me.Opacity >= 1 Then
    Do Until Me.Opacity = 0
    Me.Opacity = Me.Opacity - 0.1
    Loop
    Else
    Do Until Me.Opacity = 1
    Me.Opacity = Me.Opacity + 0.1
    Loop
    End If
    FaderTimer.Enabled = False
    End Sub

    You'd think it would work. However it actually does nothing.
    The form initially starts minimised, and no matter how much you click on the system icon, nothing happens.

    I've played and tweaked and done all sorts of messing around - i even managed to get the error message to fade in and out!! (just dont ask how!), but cant it to work.

    I presume that since the form starts minimised, I need to unminimise it. However the only way I know to do that would be to use Me.Show() -but surely that would bypass the fader completely?

    Any ideas?

    Cheers guys!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Brisbane, Australia
    Posts
    50
    Rep Power
    12

    Re: Fading forms into and out of sight


    Originally posted by Pain
    Code:
    Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
      FaderTimer.Enabled = True
    End Sub
    
    Private Sub FaderTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FaderTimer.Tick
      If Me.Opacity >= 1 Then
        Do Until Me.Opacity = 0
          Me.Opacity = Me.Opacity - 0.1
        Loop
      Else
        Do Until Me.Opacity = 1
          Me.Opacity = Me.Opacity + 0.1
        Loop
      End If
      FaderTimer.Enabled = False
    End Sub
    try change it to
    Code:
    private fading as boolean = false 'a class variable
    Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
      fading = Me.Visible
      if not Fading then
        Me.Opacity = 0
        Me.Show()
      end if
      FaderTimer.Enabled = True
    End Sub
    
    Private Sub FaderTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FaderTimer.Tick
      if fading then
        if Me.Opacity >= 0.1 then
          Me.Opacity = My.Opacity - 0.1
        else
          me.hide()
          FaderTimer.Enabled = False
        end if
      else
        if Me.Opacity <= 0.9 then
          Me.Opacity = My.Opacity += 0.1
        else
          FaderTimer.Enabled = False
        end if
      end if
    End Sub
    did not test the code, straight typed here.

IMN logo majestic logo threadwatch logo seochat tools logo