Results 1 to 5 of 5

Thread: [RESOLVED] Problem to stretch picture in picturebox

  1. #1

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Resolved [RESOLVED] Problem to stretch picture in picturebox

    I cannot stretch picture loaded in a picturebox according to picturebox scale. I don't know what is the problem with this code. Can anybody help me find the problem?
    VB Code:
    1. Private Sub picPatient_Click()
    2. On Error Resume Next
    3. Dim sPathPic As String, currentID As Long
    4. If rec("img_path") = "" Then
    5.     If MsgBox("Do you want to add picture?", vbYesNo + vbQuestion, "Add picture") = vbYes Then
    6.         'Add picture here
    7.         cdOpen.Filter = "JPEG |*.jpg"
    8.         cdOpen.ShowOpen
    9.         sPathPic = Replace(cdOpen.FileName, "\", "\\")
    10.         con.Execute "UPDATE maklumat_pesakit img_path SET img_path = '" & sPathPic & "' WHERE id = " & rec(0) & ";"
    11.         currentID = CLng(rec(0))
    12.         Form_Load
    13.         rec.Find "[ID] = " & currentID
    14.         Exit Sub
    15.     End If
    16. Else
    17.     If MsgBox("Do you want to remove this picture?", vbYesNo + vbQuestion, "Remove picture") = vbYes Then
    18.         con.Execute "UPDATE maklumat_pesakit img_path SET img_path = '' WHERE id = " & rec(0) & ";"
    19.         Set picPatient.Picture = Nothing
    20.         currentID = CLng(rec(0))
    21.         Form_Load
    22.         rec.Find "[ID] = " & currentID
    23.         Exit Sub
    24.     End If
    25. End If
    26. End Sub
    27.  
    28. Private Sub picPatient_Resize()
    29.     picPatient.PaintPicture picPatient.Picture, 0, 0, picPatient.ScaleWidth, picPatient.ScaleHeight
    30. End Sub

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Problem to stretch picture in picturebox

    Try putting it into the paint event
    VB Code:
    1. Private Sub picPatient_Paint()
    2.     picPatient.PaintPicture picPatient.Picture, 0, 0, picPatient.ScaleWidth, picPatient.ScaleHeight
    3. End Sub

  3. #3

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to stretch picture in picturebox

    I tried to put it into paint event but "Argument not optional" error msg appear

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Problem to stretch picture in picturebox

    Worked perfectly for me ...
    It will bring up an error if there is no image in the picturebox, but i'm not sure why its bringing up the "Argument not optional" error (the error for no picture is "Invalid Picture")

    Does it highlight any part of the code?

    Also make sure all required arguments aren't missing... maybe something might have been removed by accident
    Code:
    object.PaintPicture picture, x1, y1, [width1], [height1], [x2], [y2], [width2], [height2], [opcode]
    
    You can omit as many optional trailing arguments as you want. If you omit an optional trailing argument or arguments, don't use any commas following the last argument you specify. If you want to specify an optional argument, you must specify all optional arguments that appear in the syntax before it.
    [Optional argument]
    Last edited by Andrew G; Jan 2nd, 2007 at 09:24 PM.

  5. #5

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to stretch picture in picturebox

    Thanks andrew, it works now. I actually put , , to x1 and y1 arguments that's why it erroring. Ok thanks again.

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