How do I draw simple graphics in C#?

后端 未结 9 849
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 02:33

I just want to draw simple 2D objects like circle, line, square etc in C#. How do I do that? Back in the Turbo C++ days I remember initializing some graphics library for doi

9条回答
  •  粉色の甜心
    2020-12-10 02:59

    Here's a simple code sample that will get you started (assumes you have a PictureBox named pictureBox1):

    Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
    using (Graphics g = Graphics.FromImage(bmp))
    {
        g.DrawLine(new Pen(Color.Red), 0, 0, 10, 10);
    }
    pictureBox1.Image = bmp;
    

    The graphics object has a bunch of other drawing methods, and Intellisense will show you how to call them.

提交回复
热议问题