this code draws an horizontal line on a PictureBox.
Code:
void bigWindowPictureBoxCamera_Paint(object sender, PaintEventArgs e)
{
PictureBox pb = (PictureBox)sender;
e.Graphics.DrawLine(Pens.Red, 0, 27, pb.Width, 27);
}
Since my PictureBox.SizeMode is PictureBoxSizeMode.Zoom I'd like to paint the line on the Image only (not in the unused grey area of the PictureBox).
I tried the following:
Code:
void bigWindowPictureBoxCamera_Paint(object sender, PaintEventArgs e)
{
PictureBox pb = (PictureBox)sender;
Graphics graphics = Graphics.FromImage(pb.Image);
graphics.DrawLine(Pens.Red, 0, 27, pb.Image.Width, 27);
}
With the above code, the line appears on the Image only (in the correct coordinates), but only a few times (when resizing the form, the line appears and disappears, mainly it's not visible).
I got back to the first code (using e.Graphics), trying to figure out how to get the Image coordinates from the PictureBox.
Can anybody help me doing that?