473,503 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fade-In Form

Hey guys I am trying to fade in a form using the following code:

Public Class frmAbout
Inherits System.Windows.Forms.Form

Dim i As Integer 'Public Variable

#Region The Windows Form code...
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If i < 100 Then
i = i + 1
Me.Opacity = i / 100
Else
Timer1.Stop()
End If
End Sub
End Class

I tried adjusting my timer to various values (currently 500000 as I am
not sure what this number corresponds to) and my timer is started in my
form initialization code. Yet my form does not fade in, it kinda blinks
and just appears. In the function that creates the form I have:

Dim objAbout = New frmAbout()
objAbout.MdiParent = Me
objAbout.Show()

Any ideas on why my form is not fading in?
(THe opacity is set to 0 in the properties window in design view of the
form)

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
14 2247
Ivan:

I have an article over here
http://www.knowdotnet.com/testsite/a...s/opacity.html . It's in C# but it
should help. BTW, we are still proofing the grammar, but the code is
correct. HTH,

Bill
"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl...
Hey guys I am trying to fade in a form using the following code:

Public Class frmAbout
Inherits System.Windows.Forms.Form

Dim i As Integer 'Public Variable

#Region The Windows Form code...
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If i < 100 Then
i = i + 1
Me.Opacity = i / 100
Else
Timer1.Stop()
End If
End Sub
End Class

I tried adjusting my timer to various values (currently 500000 as I am
not sure what this number corresponds to) and my timer is started in my
form initialization code. Yet my form does not fade in, it kinda blinks
and just appears. In the function that creates the form I have:

Dim objAbout = New frmAbout()
objAbout.MdiParent = Me
objAbout.Show()

Any ideas on why my form is not fading in?
(THe opacity is set to 0 in the properties window in design view of the
form)

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
Ivan:

Also, you may want to move the Sleep increment down to 70 or even 50
depending on how fast/slow your machine works, but this can defintiely do it
without flicker.

HTH,

Bill
"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:Of**************@TK2MSFTNGP11.phx.gbl...
Hey guys I am trying to fade in a form using the following code:

Public Class frmAbout
Inherits System.Windows.Forms.Form

Dim i As Integer 'Public Variable

#Region The Windows Form code...
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
If i < 100 Then
i = i + 1
Me.Opacity = i / 100
Else
Timer1.Stop()
End If
End Sub
End Class

I tried adjusting my timer to various values (currently 500000 as I am
not sure what this number corresponds to) and my timer is started in my
form initialization code. Yet my form does not fade in, it kinda blinks
and just appears. In the function that creates the form I have:

Dim objAbout = New frmAbout()
objAbout.MdiParent = Me
objAbout.Show()

Any ideas on why my form is not fading in?
(THe opacity is set to 0 in the properties window in design view of the
form)

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #3
I tried inserting this code into my form_load and removing my other code
utilizing the timer:

Dim i As Double = 0.0

For i = 0.0 To i >= 1.0
Me.Opacity = i
i = i + 0.1
System.Threading.Thread.Sleep(500)
Next
Me.Opacity = 1

However, it does the same thing. It kind of hesitates and than just
shows up, there is no fade in.

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Change the 500 to 50 for instance. It may be your video card isn't
processing it quickly. I've run this on quite a few machines and at 500
it's somewhat choppy but it's not that bad. At 100 it's pretty smooth and
at 70 it's the exact effect I want. If you go too low, it happens too
quickly. Too slow and it's choppy.

You may also want to play with the increment. I have it set at .1. but you
can change it to .05 for instance, or even .01 to fine tune it. If you use
a smaller increment though, don't use 500 for the thread, it'll be 10 times
as long at .01 and twice as long at .05. I'd move the sleep to 100 first,
if that doesn't do it, try 70, then maybe 50. If it's still choppy, go back
start at like 200 and play with the increment. It's going to be a matter of
playing with it, but remember that you may want to make it adjustable b/c
different video cards draw things at different speeds and the users may want
the ability to manipulate it themseleves.

One other thing.... Try adding a DoEvents in the loop. Normally I refrain
from this, but I'm thinking it may help in this case.

Let me know.

Bill
"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:Of****************@TK2MSFTNGP10.phx.gbl...
I tried inserting this code into my form_load and removing my other code
utilizing the timer:

Dim i As Double = 0.0

For i = 0.0 To i >= 1.0
Me.Opacity = i
i = i + 0.1
System.Threading.Thread.Sleep(500)
Next
Me.Opacity = 1

However, it does the same thing. It kind of hesitates and than just
shows up, there is no fade in.

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #5
I think what is happening is that when I call the show method of the
About form from my menu (main MDI Form) it is running this code before
the form actually shows. I am not sure but I think that is what the
problem is.

The structure is:

User Clicks on Help-->About Menu Item
I create a new About form object and set its mdi parent to the main MDI
form.
I than call objAbout.Show()
the code to fade-in my form is in the frmAbout_Load event.

Maybe it is this structure that is giving me my trouble?

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #6
put an application.doevents() in the loop, this causes all the events in the
queue to process... sometimes that holds up paining of forms if you dont do
it when its in a loop
"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:Of****************@TK2MSFTNGP10.phx.gbl...
I tried inserting this code into my form_load and removing my other code
utilizing the timer:

Dim i As Double = 0.0

For i = 0.0 To i >= 1.0
Me.Opacity = i
i = i + 0.1
System.Threading.Thread.Sleep(500)
Next
Me.Opacity = 1

However, it does the same thing. It kind of hesitates and than just
shows up, there is no fade in.

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #7
I tried moving my code to the activated method after reading a reference
noticing that the form load method runs before the form is painted so
the code would be useless there.

No luck with the following code:

Maybe e-mailing you the actual code would help. I am so confused with
this problem.

Private Sub frmAbout_Activated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Dim i As Double = 0.0

While i < 1.0
'Application.DoEvents()
Me.Opacity = i
i = i + 0.01
System.Threading.Thread.Sleep(50)
End While
'Me.Opacity = 1
End Sub

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #8
do somethign similar to this

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim fadeThread As New System.Threading.Thread(AddressOf fadeIn)

fadeThread.Start()

End Sub

Public Sub fadeIn()

Application.DoEvents()

Me.Refresh()

For x As Double = 0 To 1.0 Step 0.01

Me.Opacity = x

System.Threading.Thread.Sleep(50)

Next

End Sub

"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I tried moving my code to the activated method after reading a reference
noticing that the form load method runs before the form is painted so
the code would be useless there.

No luck with the following code:

Maybe e-mailing you the actual code would help. I am so confused with
this problem.

Private Sub frmAbout_Activated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Dim i As Double = 0.0

While i < 1.0
'Application.DoEvents()
Me.Opacity = i
i = i + 0.01
System.Threading.Thread.Sleep(50)
End While
'Me.Opacity = 1
End Sub

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #9
you will have to set the initial opacity to zero also, using a thread like
this makes the form usable while it fades in also... change the sleep time
to make it go faster also
"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I tried moving my code to the activated method after reading a reference
noticing that the form load method runs before the form is painted so
the code would be useless there.

No luck with the following code:

Maybe e-mailing you the actual code would help. I am so confused with
this problem.

Private Sub frmAbout_Activated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Dim i As Double = 0.0

While i < 1.0
'Application.DoEvents()
Me.Opacity = i
i = i + 0.01
System.Threading.Thread.Sleep(50)
End While
'Me.Opacity = 1
End Sub

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #10
just a little bug to that, the opacity only reaches .99 at the end, you
might want to make a better loop or set the opacity at the end of the fadein
sub to be 1..
also the step will change how much the fade does to, like .01 does 100
levels of fade, while .1 does only 10...
"Brian Henry" <[REMOVE-ME]br******@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
do somethign similar to this

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim fadeThread As New System.Threading.Thread(AddressOf fadeIn)

fadeThread.Start()

End Sub

Public Sub fadeIn()

Application.DoEvents()

Me.Refresh()

For x As Double = 0 To 1.0 Step 0.01

Me.Opacity = x

System.Threading.Thread.Sleep(50)

Next

End Sub

"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I tried moving my code to the activated method after reading a reference
noticing that the form load method runs before the form is painted so
the code would be useless there.

No luck with the following code:

Maybe e-mailing you the actual code would help. I am so confused with
this problem.

Private Sub frmAbout_Activated(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
Dim i As Double = 0.0

While i < 1.0
'Application.DoEvents()
Me.Opacity = i
i = i + 0.01
System.Threading.Thread.Sleep(50)
End While
'Me.Opacity = 1
End Sub

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 20 '05 #11
Hi Ivan,

That is the answer - I was having the same problem - simply do not set a
parent and the form will fade in just fine.

HTH,

Bernie Yaeger

"Ivan Weiss" <iv*****@optonline.net> wrote in message
news:Oq**************@TK2MSFTNGP11.phx.gbl...
I think what is happening is that when I call the show method of the
About form from my menu (main MDI Form) it is running this code before
the form actually shows. I am not sure but I think that is what the
problem is.

The structure is:

User Clicks on Help-->About Menu Item
I create a new About form object and set its mdi parent to the main MDI
form.
I than call objAbout.Show()
the code to fade-in my form is in the frmAbout_Load event.

Maybe it is this structure that is giving me my trouble?

-Ivan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #12
On Sun, 14 Dec 2003 18:07:49 -0800, Ivan Weiss wrote:
For i = 0.0 To i >= 1.0


This syntax makes no sense to me. The i >= 1.0 clause will evaluate to a
boolean False. So you're really saying For i = 0.0 To False. That makes
no sense to me. Do you have Option Strict On?

Try this:

Dim i as Double

For i = 0.0 to 1.0 Step 0.01
Me.Opacity = i
System.Threading.Thread.Sleep(500)
Next

Does that make any difference?

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #13
u know that works and all but it will never reach 1.0 ;) stepping by .01
will get you up to .99 then drop out... duno why exactly.. but it does...
look at the code i posted... it only getsup to 99% opacity when i tested it
many times... had to manually set it to 1.0 myself to get 100%
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1l****************************@40tude.net...
On Sun, 14 Dec 2003 18:07:49 -0800, Ivan Weiss wrote:
For i = 0.0 To i >= 1.0


This syntax makes no sense to me. The i >= 1.0 clause will evaluate to a
boolean False. So you're really saying For i = 0.0 To False. That makes
no sense to me. Do you have Option Strict On?

Try this:

Dim i as Double

For i = 0.0 to 1.0 Step 0.01
Me.Opacity = i
System.Threading.Thread.Sleep(500)
Next

Does that make any difference?

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #14
u know that works and all but it will never reach 1.0 ;) stepping by .01
will get you up to .99 then drop out... duno why exactly.. but it does...
look at the code i posted... it only getsup to 99% opacity when i tested it
many times... had to manually set it to 1.0 myself to get 100%
"Chris Dunaway" <dunawayc@_lunchmeat_sbcglobal.net> wrote in message
news:1l****************************@40tude.net...
On Sun, 14 Dec 2003 18:07:49 -0800, Ivan Weiss wrote:
For i = 0.0 To i >= 1.0


This syntax makes no sense to me. The i >= 1.0 clause will evaluate to a
boolean False. So you're really saying For i = 0.0 To False. That makes
no sense to me. Do you have Option Strict On?

Try this:

Dim i as Double

For i = 0.0 to 1.0 Step 0.01
Me.Opacity = i
System.Threading.Thread.Sleep(500)
Next

Does that make any difference?

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.

Nov 20 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1652
by: Acer | last post by:
Does somebody know a javascript function to show an image and fade-out to another picture ? thanks for any help
2
2048
by: Harshal | last post by:
Hello, I have following html file <html> <head> <script> var flag = true; function LoadNewImage()
2
1785
by: localhost | last post by:
I want to read an image from disk, get the total width, and then find the bottom region (say an area of 120 high x the total width) and fade-away each pixel by a percentage to white, and then...
1
3073
by: Theseus | last post by:
Hello to all, I've got an issue where i don't know what solution i can implement. I'm not sure what script best can be used. I've got samples .jpg images to better describe my problem. Stage...
1
1420
by: Michael | last post by:
I would like to create my own system that allows dragging and dropping, into different cells of a table, much like Yahoo's implementation here: http://developer.yahoo.com/yui/dragdrop/index.html ,...
1
1991
by: John Smith | last post by:
I'm looking for javascript that will rotate 3-6 jpg images with a fade to white transition between images. I've got a script that will handle the rotation but not the fade. Maybe it can't be...
3
14421
by: virgil46 | last post by:
How do I for instance, fade the background color from dark gold at the top of the page to a light gold, by the time it gets to the bottom of the page?
5
3263
by: Gretsch | last post by:
Hi, Can someone help me with the command format please. I have a function (called fade) that was 3 parameters: the first 2 are colours therefore formatted #123456 and the 3rd is a number of...
4
4944
by: pt36 | last post by:
Hi I have a small script function photo(a){ var photo = a ; document.getElementById(photoID).innerHTML = photo; } and on the body
3
3504
toxicpaint
by: toxicpaint | last post by:
Hi Everyone, I've had a look around but couldn't find any answers so thought I'd ask you lot. :) I'm using actionscript 2.0. What I have on my stage is a button that when you mouse over it,...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1510
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.