2
Answers

C# - Can't call a new pen. Did I miss something?

Ask a question
Anthony

Anthony

16y
2.5k
1

Okay, I am trying to make a custom pen to draw a simple border around a picture, but for some reason, I get a message saying that
"System.Drawing.Pen does not have a definition for objSteelSolid" I don't get this one. I declared the object under the Pen type, but it still doesn't recognise it as a pen? What gives?

private void btnDrawBorder_Click(object sender, EventArgs e)
{
Graphics objGraphics = null;
objGraphics =
this.CreateGraphics();
objGraphics.Clear(
SystemColors.Control);

//new pen
Pen objSteelSolid = new Pen(Color.SteelBlue, 5);
objMyPen.DashStyle = System.Drawing.Drawing2D.
DashStyle.Solid;

objGraphics.DrawRectangle(
Pen.objSteelSolid, //ERROR!
picBox.Left - 1, picBox.Top - 1,
picBox.Width + 1, picBox.Height + 1);
objGraphics.Dispose();
}


Answers (2)