Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
After playing with the code below for a few days I stumped at whats going wrong
with the routine. Since this is a part of a larger project I broke the code down to a small section to run on a test form to debug the problem.

Its very basic a form with a picture box 164 by 130 pixels. I use a solid color box to get a better view of what going on.

If you try the code it will shrink the box just like I wanted. But then when I reverse the process it goes all wrong.

Any suggestions would be a greatly appreciated...

VB
Public Class Form1

    Public PBH As Integer
    Public PBW As Integer
    Public times As Integer
    Public locx As Integer
    Public locy As Integer

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

        Timer1.Enabled = True ' Turn On Timer Tick

        PBH = 130 ' Set Picturebox height to 130

        PBW = 164 ' Set Picturebox width to 164

        times = 10 ' Number of timer to run routine before exit

        locx = 60

        locy = 60

    End Sub

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

        Do                           ' start main loop to shrink PB1

            PictureBox1.Height = PBH ' Reset Picturebox 1 Height
            PictureBox1.Width = PBW '  Reset Picturebox 1 Width

            PictureBox1.Location = New Point(locx, locy) ' Reset x.y pos

            PBH = PBH - 1 : PBW = PBW - 1 : locx = locx + 1 : locy = locy + 1 ' Decrease size of PB increase location x,y

            Call Delay() ' Slow down graphics for effect

            If PBH > 0 Then Continue Do ' Keep making it smaller if limit not reached

        Loop Until PBH = 0  ' If limit is reached then move to next loop

        PBH = 1 : PBW = 35 ' Reset starting points for Picturebox 1

        Do                           ' Start to make PB1 Larger again

            PictureBox1.Height = PBH ' Reset Picturebox 1 Height
            PictureBox1.Width = PBW '  Reset Picturebox 1 Width

            PictureBox1.Location = New Point(locx, locy) ' Increase location x,y

            PBH = PBH + 1 : PBW = PBW + 1 : locx = locx - 1 : locy = locy - 1 ' Increase size of PB1

            Call Delay() ' Slow down for graphics effect

            If PBH < 130 Then Continue Do ' Keep going until limit is reached

        Loop Until PBH = 130 : Timer1.Enabled = False ' Once limits is reached turnoff timer tick

    End Sub

    Public Sub Delay()

        For t = 1 To 2500000 : Next t

    End Sub

End Class
Posted
Comments
Sergey Alexandrovich Kryukov 27-Feb-13 16:22pm    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

Hello

Add a call to the Update() method to force the picturebox to redraw it's content.

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.update.aspx[^]

VB
PictureBox1.Height = PBH ' Reset Picturebox 1 Height
PictureBox1.Width = PBW '  Reset Picturebox 1 Width

PictureBox1.Location = New Point(locx, locy) ' Increase location x,y
PictureBox1.Update()





Valery
 
Share this answer
 
You should never use PictureBox for anything dynamic, interactive, animated, etc. It's possible, but makes no sense at all. It's pretty apparent that to do instead. Please see my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900