Question Drawing on picture box

steozum

New member
Joined
Jan 9, 2025
Messages
1
Programming Experience
5-10
I'm drawing figures with the draw method in a picturebox contained in a form and I enlarge it to full screen the picturebox correctly increases in size. However, when I have to draw the lines (or circles) they are interrupted. It seems that they remain visible only on the original size of the picturebox, what am I doing wrong?
Img.JPG
 
what am I doing wrong?

That's a hard question to answer when we don't actually know what you're doing. Please provide a FULL and CLEAR explanation of what you're trying to achieve, how you're trying to achieve it and what happens when you try. Assuming that you are correctly using the Paint event, the drawing still won't change because the size of the control changed if you're using absolute values to control the drawing. You'd have to be using proportional values but you've provided us with no evidence either way. We should not have to make assumptions or guess. You should provide ALL the relevant information.
 
You draw on a Control's surface using the Graphics object provided by "PaintEventArgs" or this method below.
This example uses the mouse to do so:

DRAW ON PICTUREBOX:
Private _Previous As System.Nullable(Of Point) = Nothing
Private Sub pictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
_Previous = e.Location
pictureBox1_MouseMove(sender, e)
End Sub

Private Sub pictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove
If _Previous IsNot Nothing Then
If PictureBox1.Image Is Nothing Then
Dim bmp As New Bitmap(PictureBox1.Width, PictureBox1.Height)
Using g As Graphics = Graphics.FromImage(bmp)
g.Clear(Color.White)
End Using
PictureBox1.Image = bmp
End If
Using g As Graphics = Graphics.FromImage(PictureBox1.Image)
g.DrawLine(Pens.Black, _Previous.Value, e.Location)
End Using
PictureBox1.Invalidate()
_Previous = e.Location
End If
End Sub

Private Sub pictureBox1_MouseUp(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseUp
_Previous = Nothing
End Sub
 
Back
Top