user1594121
user1594121

Reputation: 117

Draw an outline of form with graphics

Basically I have a form with no border, I want to keep it like that. It's in a fixed position. I'm trying to draw an outline of the form size in the form (so it looks like a border) I'm having trouble and never really used "drawing" techniques in forms.

Pen pen = new Pen(Color.Black, 20);
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
Graphics g = CreateGraphics();
g.DrawRectangle(pen, rect);

Upvotes: 0

Views: 1098

Answers (1)

Simon Whitehead
Simon Whitehead

Reputation: 65087

Do it in OnPaint:

protected override void OnPaint(PaintEventArgs e) {
    base.OnPaint(e);
    Pen pen = new Pen(Color.Black, 20);
    Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
    e.Graphics.DrawRectangle(pen, rect);
}

Upvotes: 3

Related Questions