Click here to Skip to main content
13,091,300 members (52,917 online)
Rate this:
 
Please Sign up or sign in to 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...

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 7-Feb-13 10:35am
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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[^]

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 26 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100