|
-
Jul 23rd, 2004, 12:37 PM
#1
Thread Starter
New Member
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.
-
Jul 23rd, 2004, 12:52 PM
#2
Lively Member
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:
If Me.Opacity < 1 then
Me.Opacity += 0.01
Else
FadeTimer.Enabled = False
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? ? ? ! ! !
-
Jul 23rd, 2004, 12:56 PM
#3
Thread Starter
New Member
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.
-
Jul 23rd, 2004, 05:24 PM
#4
Lively Member
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:
If Me.Opacity > 0 then
Me.Opacity -= 0.01
Else
FadeOutTimer.Enabled = False
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? ? ? ! ! !
-
Jul 23rd, 2004, 05:31 PM
#5
Thread Starter
New Member
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:
Public Class FaderForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents FadeInTimer As System.Windows.Forms.Timer
Friend WithEvents CloseTimer As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(FaderForm))
Me.FadeInTimer = New System.Windows.Forms.Timer(Me.components)
Me.CloseTimer = New System.Windows.Forms.Timer(Me.components)
'
'FadeInTimer
'
Me.FadeInTimer.Enabled = True
Me.FadeInTimer.Interval = 1
'
'CloseTimer
'
Me.CloseTimer.Interval = 1
'
'FaderForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
Me.ClientSize = New System.Drawing.Size(542, 216)
Me.ControlBox = False
Me.Enabled = False
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "FaderForm"
Me.Opacity = 0
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
End Sub
#End Region
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 > 0 Then
Me.Opacity -= 0.01
Else
CloseTimer.Enabled = False
End If
End Sub
Private Sub FaderForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ShowInTaskbar = False
End Sub
End Class
Hope this helps. Thanks
-
Jul 23rd, 2004, 06:00 PM
#6
PowerPoster
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:
Private Sub FadeInTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeInTimer.Tick
If Me.Opacity < 1 Then
Opacity += 0.01
Else
FadeInTimer.Enabled = False
End If
CloseTimer.Enabled = True
End Sub
-
Jul 23rd, 2004, 06:37 PM
#7
PowerPoster
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.
-
Jul 23rd, 2004, 07:06 PM
#8
Thread Starter
New Member
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:
Private Sub FadeInTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeInTimer.Tick
If Me.Opacity < 1 Then
Opacity += 0.01
Else
FadeInTimer.Enabled = False
End If
FadeOutTimer.Enabled = True
End Sub
Private Sub FadeOutTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FadeOutTimer.Tick
If Me.Opacity > 0 Then
Me.Opacity -= 0.01
Else
FadeOutTimer.Enabled = False
End If
End Sub
Did I do something wrong? I have FadeInTimer enabled and FadeOutTimer disabled.
-
Jul 23rd, 2004, 07:47 PM
#9
Thread Starter
New Member
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
-
Jul 23rd, 2004, 09:23 PM
#10
Fanatic Member
-
Jul 23rd, 2004, 11:13 PM
#11
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|