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();
}
AlanPosted Jul 26, 2008, 7:53 AM
Well, objSteelSolid is the name of a local variable which holds a reference to your new Pen object. So you just want to call DrawRectangle like this:
objGraphics.DrawRectangle(objSteelSolid,
picBox.Left - 1, picBox.Top - 1,
picBox.Width + 1, picBox.Height + 1);
I'm also wondering about this line:
objMyPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
Is objMyPen another Pen variable you have or should that line have been:
objSteelSolid.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
AnthonyPosted Jul 26, 2008, 1:08 PM