I am trying to just draw a Rectangle on a PictureBox that is on a Form.
Writing text like shown here works fine.
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
using (Font myFont = new Font("Arial", 14))
{
e.Graphics.DrawString("Hello .NET Guide!", myFont, Brushes.Green, new Point(2, 2));
}
}
but when I try to draw a rectangle like so nothing shows up.
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle();
rect.Location = new Point(25, 25);
rect.Width = 50;
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, rect);
}
}
What am I missing?