Reputation: 4103
I have a problem that I am creating a rectangle in a picturebox through PictureBox1_Paint() event but when we call the constructor of Rectangle class it shows an error as Rectangle class does not contain a constructor that takes 4 arguments, I don't know how to resolve this and also where I go wrong? Please suggest me for the right solution regarding the same.
Code:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Rectangle ee = new Rectangle(10, 10, 30, 30);
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, ee);
}
}
Upvotes: 0
Views: 1963
Reputation: 40736
Probably you included a namespace (through the using
directive at the very beginning of your .CS file) that includes a Rectangle
class/structure that has the same name but otherwise is non-related to the Rectangle
structure.
Try the absolute name like:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Rectangle ee = new System.Drawing.Rectangle(10, 10, 30, 30);
using (Pen pen = new Pen(Color.Red, 2))
{
e.Graphics.DrawRectangle(pen, ee);
}
}
I.e. use System.Drawing.Rectangle
instead of just Rectangle
.
Upvotes: 6