CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Help with resizing the PictureBox contorl if the Picture is too big.

    I need to be able to have VB automatically make the picturebox go back to it's normal siz if the imported picture is too big. This is what I have so far
    private Sub Picture1_Resize()
    If Picture1.ScaleHeight > "33" Or Picture1.ScaleWidth > "41" then MsgBox "Too Big!", vbCritical
    If Picture1.ScaleHeight > "33" Or Picture1.ScaleWidth > "41" then Picture1.ScaleHeight = (33) And Picture1.ScaleWidth = (41)
    End Sub

    can anyone help me? Thanks!


  2. #2
    Guest

    Re: Help with resizing the PictureBox contorl if the Picture is too big.

    Something would have to occur to invoke the Resize event. Try the Paint event.
    Also, try putting the loaded picture into an Image control (which would be on your PictureBox).
    Then in the "Picture Paint" event, resize your Picture to equate with the size of the Image control.
    Since the Image control will automatically resize to fit the picture.
    If the picture is larger than the screen you will have to use a Scrollbar on the form to move the picture up and down,
    and make the picture larger than the screen.


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Help with resizing the PictureBox contorl if the Picture is too big.

    Try setting the Picture box's AutoSize Property to True, it should fire Resize event.

    private Sub Picture1_Resize()
    static bstillinside as boolean
    if bStillInside then exit sub
    bSitllInside = true
    with Picture1
    Debug.Assert .ScaleMode = VbPixels ' is my assumption correct?
    If .ScaleHeight > "33" Or _
    .ScaleWidth > "41" then
    MsgBox "Too Big!", vbCritical
    .Move .Left , .Top , 37 , 45
    ' this line will triger another _Resize Event, and we need to block it so that
    ' we dont end up in recursive loops
    ' Also, setting the scaleWidth will not change the size, instead it will make the ScaleMode to "User", and take those values
    ' You need to play around with the values.
    ' for width & height.
    ' it depends on the BorderStyle, and Appearence. If both are on then it is usally 3 Pixels
    ' Or try using GetWindowRect and GetClientRect, and maintain the same difference.
    end if
    ' dont forget this:
    bStillInside = false
    End Sub




    RK

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

Featured