Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to make a rectangle shrink using a timer or something 1

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
0
36
US
here is my code so far, not much.
I want to make the rectangle shrink using a timer, say every 1/2 second.
Any Ideas?
Code:
    Private Sub DeactivateTrackerBeam_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        e.Graphics.DrawRectangle(Pens.DarkOrange, 150, 250, 600, 100)

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' rectangle size shrinks from 600 down to 0
    End Sub

DougP, MCP, A+
 
Maybe something like this:

Code:
  Private rect As Rectangle

  Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

    rect = New Rectangle(10, 10, 150, 25)
    Dim g As Graphics = Panel1.CreateGraphics
    g.DrawRectangle(Pens.DarkOrange, rect)
    g = Nothing
    Timer1.Enabled = True

  End Sub

  Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    If rect.Width = 10 Then Timer1.Enabled = False
    Dim g As Graphics = Panel1.CreateGraphics
    Dim p As New Pen(Panel1.BackColor)
    g.DrawRectangle(p, rect)
    rect.Width = rect.Width - 10
    g.DrawRectangle(Pens.DarkOrange, rect)
    g = Nothing

  End Sub

I put the rectangle on a Panel and used a smaller start rectangle, but that should be easy enough for you to modify.


Hope this helps.

[vampire][bat]
 
Hi,

I think something like this should work :

Code:
 Private Sub DeactivateTrackerBeam_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        e.Graphics.DrawRectangle(Pens.DarkOrange, 150, 250, somesize, 100)

    End Sub

private someSize as integer = 600
private shrinkSize as integer = 50
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
' rectangle size shrinks from 600 down to 0
someSize -= shrinkSize 
me.refresh()
    End Sub

hope it helps
 
This isn't my post, but I thought EandA deserved a star. I don't know if or when I'll use it, but it's handy code.

Thanks...

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top