C#程序绘图应用题。

:考核 Window 窗体下,基本的绘图工具的应用:画直线(DrawLine)、画矩形(DrawRectangle)、画椭圆(DrawEllipse)、画字符(DrawString)以及图形的填充(FillRectangle、FillEllipse)。

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

        Graphics g = e.Graphics;

        // 画直线
        Pen pen = new Pen(Color.Black, 2);
        g.DrawLine(pen, 50, 50, 200, 200);

        // 画矩形
        g.DrawRectangle(pen, 100, 100, 200, 150);

        // 画椭圆
        g.DrawEllipse(pen, 300, 100, 150, 150);

        // 画字符
        Font font = new Font("Arial", 12);
        SolidBrush brush = new SolidBrush(Color.Black);
        g.DrawString("Hello, World!", font, brush, 50, 250);

        // 填充矩形
        SolidBrush rectBrush = new SolidBrush(Color.Red);
        g.FillRectangle(rectBrush, 100, 300, 200, 100);

        // 填充椭圆
        SolidBrush ellipseBrush = new SolidBrush(Color.Blue);
        g.FillEllipse(ellipseBrush, 300, 300, 150, 100);
    }