我是C#的新手,正在努力以表格形式画线。这是我到目前为止的代码。

Graphics g;

g = this.CreateGraphics();

Pen myPen = new Pen(Color.Red);
myPen.Width = 30;
g.DrawLine(myPen, 30, 30, 45, 65);

g.DrawLine(myPen, 1, 1, 45, 65);

最佳答案

试试OnPaint

protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g;

            g = e.Graphics;

            Pen myPen = new Pen(Color.Red);
            myPen.Width = 30;
            g.DrawLine(myPen, 30, 30, 45, 65);

            g.DrawLine(myPen, 1, 1, 45, 65);
        }

10-08 19:27