Damir Bojan
Damir Bojan

Reputation: 107

Drawing on picturebox vs directly on form

I am creating a lightweight GDI+ game engine in c#. I read some books that use a picturebox control as the graphics surface to draw on when creating a game engine. However after doing some research online it seems as if using a picturebox control is not what I should be doing. Is this true and if so why?

Upvotes: 3

Views: 1421

Answers (1)

King King
King King

Reputation: 63367

You don't need any control, just draw directly on your form or a Panel with DoubleBuffered enabled. It's much better. You have to create your own objects so that we can calculate their Region, we'll use their Region to fill them on the form/panel. You have to handle the events MouseMove, MouseDown, MouseUp of your form/panel. Another problem is how to hittest your mouse with your objects so that we can control the objects according to the user behaviors. There is a useful method to do that called IsVisible of the Region object.

The reason we should not use any control for drawing here is we need some Transparent effect overlapped between objects, using winforms control can't help you achieve that easily if not wanting to say impossible, even you can achieve that, the effect is very poor. So just drawing everything on the same canvas. You should also try drawing on an Image instead, then draw that Image on your form/panel or implement your own Double or triple buffered. There are a lot to do but I hope you have some important notes with my answer and choose the right direction.

Upvotes: 2

Related Questions