miroxlav
miroxlav

Reputation: 12204

Custom drawing using System.Windows.Forms.BorderStyle?

I want to mimick drawing of default border based on value of property BorderStyle. Instead of single border around the control, my control is visualised as four adjacent custom-drawn boxes (2×2), each having standard border drawn individually. So for example, if Control.Border is set to FixedSingle value I want to draw single border around each box. Simplified example:

enter image description here

I have two related problems:

Upvotes: 1

Views: 1125

Answers (1)

TaW
TaW

Reputation: 54453

If you want to get results that reliably look like the BorderStyles on the machine you should make use of the methods of the ControlPaint object.

For testing let's do it ouside of a Paint event:

Panel somePanel = panel1;

using (Graphics G = somePanel.CreateGraphics())
{
    G.FillRectangle(SystemBrushes.Window, new Rectangle(11, 11, 22, 22));
    G.FillRectangle(SystemBrushes.Window, new Rectangle(44, 44, 66, 66));
    G.FillRectangle(SystemBrushes.Window, new Rectangle(11, 44, 22, 66));
    G.FillRectangle(SystemBrushes.Window, new Rectangle(44, 11, 66, 22));

    ControlPaint.DrawBorder3D(G, new Rectangle(11, 11, 22, 22));
    ControlPaint.DrawBorder3D(G, new Rectangle(44, 44, 66, 66));
    ControlPaint.DrawBorder3D(G, new Rectangle(11, 44, 22, 66));
    ControlPaint.DrawBorder3D(G, new Rectangle(44, 11, 66, 22));
}

Console.WriteLine("BorderSize.Width = " + SystemInformation.BorderSize.Width);
Console.WriteLine("Border3DSize.Width = " + SystemInformation.Border3DSize.Width);

On my machine this results in a screenshot similar to yours..:

enter image description here

..and these lines in the output:

BorderSize.Width = 1

Border3DSize.Width = 2

Upvotes: 1

Related Questions