用图形绘制表格轮廓

时间:2012-12-19 23:36:30

标签: c# winforms drawing

基本上我有一个没有边框的表格,我想保持这样。它处于固定的位置。我正在尝试在表单中绘制表单大小的轮廓(所以它看起来像一个边框)我遇到了麻烦,从未在表单中使用过“绘图”技术。

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

1 个答案:

答案 0 :(得分:3)

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);
}