Click here to Skip to main content
15,896,727 members

Picturebox Reshape at runtime

Dr David Johnson PhD asked:

Open original thread
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
Tags: Visual Basic (Visual Basic 8 (2005))

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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