bit of vb.net help

Soldato
Joined
11 Jan 2005
Posts
9,961
Location
Birmingham
So I want to make a form that on button click, resizes to a set width (from 250 to 500) with a timer so its "smooth" and not instant.

I can get it to initiate the movement, but then it carries on and by the looks of it my loop goes wild :D


Heres what I have, without the timer part really,

If Me.Width <= 500 Then
Do
Me.Width = Me.Width + 20
Loop Until Me.Width = 500
End If

Btw, I hate programming, so its not great! But howcome my loop doesnt halt when me.width = 500? :confused:


I've no idea how to attempt it with a timer,

everytime timer interval ticks me.width = me.witch + 1 etc..

Help :)
 
Well, if you're starting at 250, then adding 20 each time gives:
270, 290, 310, 330, 350, 270, 390, 410, 430, 450, 470, 490, 510, etc.

...so your condition of Me.Width = 500 is never met.

And this shouldn't really be done like this, as I imagine it'll complete so quickly that it's barely noticeable. As you said you need to do it with a timer to get the desired smoothness.

You could do it something like this:
Code:
Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
    Me.Width += increment
End Sub
...where increment is the width to increase by on each tick.

You'd first need to decide how long it should take to resize the form. Once you've decided on that, you need to decide how smooth you want it to be (the smoother you want it, the smaller the timer's interval). Then you can work out the value of increment:
increment = (500 - 250) / ((time to resize) / (timer interval)).
 
Last edited:
... oh yeah :D


hmm, changed it to +10 and still same effect.
Tried +50 too, and it just zoomed to the end of my screen a bit quicker then crashed.



You'd first need to decide how long it should take to resize the form. Once you've decided on that, you need to decide how smooth you want it to be (the smoother you want it, the smaller the timer's interval). Then you can work out the value of increment: increment = (500 - 250) / ((time to resize) / (timer interval)).

Right so, to say ive never used a timer properly before :D
A "normal" speed width expansion of a form would be milliseconds, and the timer interval is based on ms, so if i set the timer interval to say 100 then time to resize represnted by 1 would take 100 passes to reach its destination?

Or I'm way off topic/too ill and bunged up and just dont know :)
 
Last edited:
Back
Top Bottom