problem with paint method of form

tyonuts

Well-known member
Joined
Dec 27, 2005
Messages
78
Location
Romania
Programming Experience
3-5
Ok, I know this isn't the place to post this, but it's a graphics problem, so...
I tried to use the following code to fade a form, after setting it's opacity to 0:

Dim i as double=0.0
For i=0 To 1 Step 0.01
Me.Opacity=Me.Opacity+i
Threading.Thread.Sleep(10)
Next i


And all I get is a black rectangle, after which the form is painted in full (without translucency). I could use a timer, but that's the problem: the timer depends on the processor. pls help
 
I don't see why that code should be producing that effect. Unless you have also set the transparencykey of the form, or used some of the control styles. But as a note when increasing the form opacity you should always set it to 1.01 as otherwise there will still be a small amount of transparency and this could slow down you app.
Also using threading.thread.sleep is going to slow down your app aswell, your telling the main UI thread to stop working for a bit. Not a good idea in my opinion unless there is a valid reason. I suggest using a timer, so long as you know the platform and the processor that your app wil be targeting setting the inteval property of the timer to the desired amount should'nt be a problem.
 
Try:

VB.NET:
[COLOR=#0000ff]While[/COLOR] Opacity < 1
    Opacity = Opacity + 0.01
    Threading.Thread.Sleep(10)
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]While[/COLOR]
 
I know, that was just a typing mistake
The fact is, i only get a black rectangle and after that, the form appears
help pls
 
Back
Top