[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? :confused:
VB Code:
Private Sub picPatient_Click()
On Error Resume Next
Dim sPathPic As String, currentID As Long
If rec("img_path") = "" Then
If MsgBox("Do you want to add picture?", vbYesNo + vbQuestion, "Add picture") = vbYes Then
'Add picture here
cdOpen.Filter = "JPEG |*.jpg"
cdOpen.ShowOpen
sPathPic = Replace(cdOpen.FileName, "\", "\\")
con.Execute "UPDATE maklumat_pesakit img_path SET img_path = '" & sPathPic & "' WHERE id = " & rec(0) & ";"
currentID = CLng(rec(0))
Form_Load
rec.Find "[ID] = " & currentID
Exit Sub
End If
Else
If MsgBox("Do you want to remove this picture?", vbYesNo + vbQuestion, "Remove picture") = vbYes Then
con.Execute "UPDATE maklumat_pesakit img_path SET img_path = '' WHERE id = " & rec(0) & ";"
Set picPatient.Picture = Nothing
currentID = CLng(rec(0))
Form_Load
rec.Find "[ID] = " & currentID
Exit Sub
End If
End If
End Sub
Private Sub picPatient_Resize()
picPatient.PaintPicture picPatient.Picture, 0, 0, picPatient.ScaleWidth, picPatient.ScaleHeight
End Sub
Re: Problem to stretch picture in picturebox
Try putting it into the paint event
VB Code:
Private Sub picPatient_Paint()
picPatient.PaintPicture picPatient.Picture, 0, 0, picPatient.ScaleWidth, picPatient.ScaleHeight
End Sub
Re: Problem to stretch picture in picturebox
I tried to put it into paint event but "Argument not optional" error msg appear
Re: Problem to stretch picture in picturebox
Worked perfectly for me :ehh:...
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]
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.