How do I draw simple graphics in C#?

2020-02-05 06:23发布

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 doing the same. Do I need to do something similar in .NET? Is it any different for 3D objects? Will things like DirectX make this any easier? Any links to tutorials or samples much appreciated.

8条回答
【Aperson】
2楼-- · 2020-02-05 07:15

You need to use GDI+.

How you do it depends slightly on what you want to draw on. You can draw on a control or a form, or you can draw on an image object. Either way, you need a System.Drawing.Graphics object which I believe is located in System.Drawing.dll.

You can instantiate a new Bitmap class and call Graphics.FromImage(myImage), and then draw using the methods on the Graphics object you just created. If you want to draw on a form or control just override the OnPaint method and look for the Graphics property on the EventArgs class.

More information on System.Drawing namespace here: http://msdn.microsoft.com/en-us/library/system.drawing.aspx

查看更多
We Are One
3楼-- · 2020-02-05 07:18

Look for Managed Direct3D graphics API in .NET Source

查看更多
登录 后发表回答