Results 1 to 11 of 11

Thread: New to vb.net and need a little help.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12

    New to vb.net and need a little help.

    Ok well im making a splash screen and I want it to fade in when opened. What I have so far is.

    Private Sub FadeInTimer_Tick(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles FadeInTimer.Tick
    If Me.Opacity = 0% Then
    Opacity += 0.01
    End If
    End Sub

    What I want it to do is detect that the opacity of the form is 0% and then raise it to 100% with the timer. I can get it to work without the IF but when I add the if it wont detect that the opacity of the form is at 0% so it doesnt raise the opacity. Maybe i am putting in the wrong opacity value for 0%. if someone could help me it would be great. Thanks.

  2. #2
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Your code doesn't work because it checks the opacity value on every tick. The opacity value is raised only when it is 0.00, so it will work only on the first tick.

    You should use something like this:
    VB Code:
    1. If Me.Opacity < 1 then
    2.   Me.Opacity += 0.01
    3. Else
    4.   FadeTimer.Enabled = False
    5. End If
    because when the opacity is 1 (100%) the timer isn't needed anymore, disable it.
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12
    Ok cool thanks. Now that I got that working I want to make it to where after fades in it fades back out and the loops. Kinda like it is pulsing. Here is what I got.

    Private Sub FadeInTimer_Tick(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles FadeInTimer.Tick
    If Me.Opacity < 1 Then
    FadeInTimer.Enabled = True
    Opacity += 0.01
    Else
    FadeInTimer.Enabled = False
    End If
    End Sub

    Private Sub CloseTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseTimer.Tick
    If Me.Opacity = 1 Then
    CloseTimer.Enabled = True
    Opacity -= 0.01
    Else
    CloseTimer.Enabled = False
    End If
    End Sub

    If you could help it would be great. Thanks.

  4. #4
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Do I like to fail people?

    This is my suggestion for a fade-out timer (I used the same algorithm as the fade-in timer...):
    VB Code:
    1. If Me.Opacity > 0 then
    2.   Me.Opacity -= 0.01
    3. Else
    4.   FadeOutTimer.Enabled = False
    5. End If

    Let's just get one point clear: here you're dealing with time-dependent values, this makes using absolute values useless, you should use the range limitation ways (<, >, <= or >=).
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12
    Well I put that in my code and nothing. Ill show you all my code so maybe you can get a better idea of things. What I want it to do is to make the splash screen pulse in and out while the main app is loading.

    VB Code:
    1. Public Class FaderForm
    2.     Inherits System.Windows.Forms.Form
    3.  
    4.  
    5. #Region " Windows Form Designer generated code "
    6.  
    7.     Public Sub New()
    8.         MyBase.New()
    9.  
    10.         'This call is required by the Windows Form Designer.
    11.         InitializeComponent()
    12.  
    13.         'Add any initialization after the InitializeComponent() call
    14.  
    15.     End Sub
    16.  
    17.     'Form overrides dispose to clean up the component list.
    18.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    19.         If disposing Then
    20.             If Not (components Is Nothing) Then
    21.                 components.Dispose()
    22.             End If
    23.         End If
    24.         MyBase.Dispose(disposing)
    25.     End Sub
    26.  
    27.     'Required by the Windows Form Designer
    28.     Private components As System.ComponentModel.IContainer
    29.  
    30.     'NOTE: The following procedure is required by the Windows Form Designer
    31.     'It can be modified using the Windows Form Designer.  
    32.     'Do not modify it using the code editor.
    33.     Friend WithEvents FadeInTimer As System.Windows.Forms.Timer
    34.     Friend WithEvents CloseTimer As System.Windows.Forms.Timer
    35.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    36.         Me.components = New System.ComponentModel.Container
    37.         Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FaderForm))
    38.         Me.FadeInTimer = New System.Windows.Forms.Timer(Me.components)
    39.         Me.CloseTimer = New System.Windows.Forms.Timer(Me.components)
    40.         '
    41.         'FadeInTimer
    42.         '
    43.         Me.FadeInTimer.Enabled = True
    44.         Me.FadeInTimer.Interval = 1
    45.         '
    46.         'CloseTimer
    47.         '
    48.         Me.CloseTimer.Interval = 1
    49.         '
    50.         'FaderForm
    51.         '
    52.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    53.         Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
    54.         Me.ClientSize = New System.Drawing.Size(542, 216)
    55.         Me.ControlBox = False
    56.         Me.Enabled = False
    57.         Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
    58.         Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
    59.         Me.Name = "FaderForm"
    60.         Me.Opacity = 0
    61.         Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    62.  
    63.     End Sub
    64.  
    65. #End Region
    66.  
    67.     Private Sub FadeInTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeInTimer.Tick
    68.         If Me.Opacity < 1 Then
    69.             FadeInTimer.Enabled = True
    70.             Opacity += 0.01
    71.         Else
    72.             FadeInTimer.Enabled = False
    73.         End If
    74.     End Sub
    75.  
    76.     Private Sub CloseTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseTimer.Tick
    77.         If Me.Opacity > 0 Then
    78.             Me.Opacity -= 0.01
    79.         Else
    80.             CloseTimer.Enabled = False
    81.         End If
    82.     End Sub
    83.  
    84.  
    85.     Private Sub FaderForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    86.         Me.ShowInTaskbar = False
    87.     End Sub
    88.  
    89. End Class

    Hope this helps. Thanks

  6. #6
    PowerPoster SuperSparks's Avatar
    Join Date
    May 2003
    Location
    London, England
    Posts
    265
    You need to enable the fade-in timer from the form load event or the If Then statement will never be reached.

    Then call the CloseTimer from the end of the Fade-in timer:

    VB Code:
    1. Private Sub FadeInTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeInTimer.Tick
    2.         If Me.Opacity < 1 Then
    3.             Opacity += 0.01
    4.         Else
    5.             FadeInTimer.Enabled = False
    6.         End If
    7.         CloseTimer.Enabled = True
    8.     End Sub
    Nick.

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    Try to make your thread titles relative to the question. Otherwise it becomes impossible to carry our a sensible search on it.
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12
    Ok well i put that code in and now nothing happens. The form wont even fade in. Here is what I have now.

    VB Code:
    1. Private Sub FadeInTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeInTimer.Tick
    2.         If Me.Opacity < 1 Then
    3.             Opacity += 0.01
    4.         Else
    5.             FadeInTimer.Enabled = False
    6.         End If
    7.         FadeOutTimer.Enabled = True
    8.     End Sub
    9.  
    10.     Private Sub FadeOutTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeOutTimer.Tick
    11.         If Me.Opacity > 0 Then
    12.             Me.Opacity -= 0.01
    13.         Else
    14.             FadeOutTimer.Enabled = False
    15.         End If
    16.     End Sub

    Did I do something wrong? I have FadeInTimer enabled and FadeOutTimer disabled.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12
    Well im not sure if this will work but i have an idea. since i dont know the language completely yet I will put it in psuedacode. Here it goes.

    Code:
    Private Sub
         Check for Opacity
         If Opacity is less that 100% then
              Increase Opacity by 0.01 for each tick of the FadeInTimer
         End If
         Check for Opacity
         Once Opacity is greater than 0% then
         Disable FadeInTimer
         Enable FadeOutTimer
    End Sub
    
    Private Sub
         Check for Opacity
         If Opacity is greater than 0%
              Decrease Opacity by 0.01 for each tick of FadeOutTimer
         End If
         Check for Opacity
         Once Opacity is  less than 100% then
         Disable FadeOutTimer
         Enable FadeInTimer
    End Sub
    It is basically like a loop. If anyone can make this work you would be of much help. Thanks

  10. #10
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    12
    Awsome ! Thanks a ton Brown Monkey. Just 2 lines of modification and it worked like a charm ! Thanks again !

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