I have a form and within the form are some controls, i want to draw some lines to act as the form boundary. Because some of the controls are dock to the sides of the form, the method below cannot be used as it only draw on the form but is later covered by the controls again.
int penWidth = 1;
Pen aPen = new Pen(Color.Red, penWidth);
e.Graphics.DrawLine(aPen, 0, 0, 0, Height);
e.Graphics.DrawLine(aPen, Width - penWidth, 0, Width - penWidth, Height);
e.Graphics.DrawLine(aPen, 0, 0, Width, 0);
e.Graphics.DrawLine(aPen, 0, Height - penWidth, Width, Height - penWidth);
i saw other solution including using a user control to 'draw' the line in the form, but i do not like that idea at all. I also though of iterate through the controls in the form as long as that are at the edge of the form, i will draw a line in them, however this doesn't work too.
foreach (Control ctl in this.Controls)
{
if (ctl.Left == 0) //at left edge
ctl.CreateGraphics().DrawLine(aPen, 0, 0, Width, Height);
}
It doesn't help at all or am i actually doing it wrong. Both the above are in the event method Form1_Paint. Is there a direct solution on drawing lines over control without the use of customize user control?
The current closest i had is
As you can see the border around the dock label box is missing.