Results 1 to 3 of 3

Thread: [RESOLVED] Change picture box scale

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2014
    Posts
    54

    Resolved [RESOLVED] Change picture box scale

    Hi.

    I can set picture box scale for the first time but after that I can't change it (For Example: Using a command button).

    Code:
    Private Sub Command1_Click()
    
    Picture1.Scale (0, 0)-(3600, 90)
    
    Picture1.Refresh
    
    
    End Sub
    
    Private Sub Form_Load()
    
    Picture1.Scale (0, 0)-(180, 90)
        
        Picture1.Line (0, 0)-(100, 0)
        
    End Sub
    The command button does not work.

    How can I change picture box scale for many times?

    Please help me.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,598

    Re: Change picture box scale

    You have to redraw the line after changing the scale.
    You should probably have the drawing as a separate sub that you can call whenever you need to redraw, in this case after you change the scale.

    Code:
    Private Sub Command1_Click()
        Picture1.Scale (0, 0)-(3600, 90)
        UpdateDrawing
    End Sub
    
    Private Sub Form_Load()
        Picture1.Scale (0, 0)-(180, 90)
        UpdateDrawing
    End Sub
    
    Private Sub UpdateDrawing()
        Picture1.Cls
        Picture1.Line (0, 0)-(100, 0)
    End Sub
    Picture1.Refresh is for triggering the Paint Event (if AutoRedraw is False), or flushing the internal drawing buffer to the screen (if AutoRedraw is True).

    For that to work, you would have to have your drawing code in or called by the Paint event, and you would have to have AutoRedraw set to False.
    Paint events are not generated if AutoRedraw is set to True.

    If AutoRedraw is set to True, then the picturebox maintains a backbuffer (aka AutoRedraw buffer), and refreshes the drawing (as is) from there and doesn't generate a Paint Event (hence the name, AutoRedraw), but it isn't technically redrawing the drawing (it doesn't know all the drawing statements you did to create the drawing), but just refreshes the screen from an internal copy of the drawing, as a bitmap.

    When you have Autoredraw set, your drawing is being done in this internal copy, not the screen, and when you're done, the screen is refreshed from this internal copy. After that, if the area over you window is "corrupted" for any reason (e.g. a window dragged over it), VB will refresh the screen from the internal AutoRedraw buffer.

    Flipping between AutoRedraw being True and False is one way to draw some semi-permanent drawing, and transitory drawing (a selection box perhaps, or a sprite following the mouse).

    If you set AutoRedraw to true and do some drawing, perhaps a grid of lines, and scale with numbers and legends, etc.
    Then you set AutoRedraw to False, you can then have code in your paint event that drawis lines, or points, or anything you want, and these will be drawn when the paint event is called.
    The convenient thing, is that if you need to redraw the data points, lines, etc., you can do a Cls and only the stuff you've drawn while AutoRedraw was False is cleared, so you don't have to redraw the grid, legends, scale etc...

    This works because when you do a Cls, VB is simply copying the internal buffer (drawn while AutoRedraw was True) to the screen, wiping out any transitory drawing done to the screen while AutoRedraw was False (e.g. from your Paint event).
    Of course, with VB6, if you are drawing periodically to the screen you don't have to have your drawing in the Paint event, you could just call it, for instance perhaps from a timer.
    Having the code in the Paint event is more for when your drawing is infrequent, but you want it to be persistent (it will be redrawn if Windows corrupts the window) by having your drawing code be executed automatically through the paint event when needed.
    Last edited by passel; Oct 26th, 2015 at 09:02 AM.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2014
    Posts
    54

    Re: Change picture box scale

    Thanks a lot

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width