Reputation: 2428
I have written a tetris game in C#.I'm drawing the shapes in picturebox by using below code.
graphics g
g = pictureBox1.CreateGraphics();
I'm drawing the next step of the shapes by cleaning every second with through timer code. My question is:it's working slowly picturebox.refresh() command and distorted display.What should I do?
I tried below function.But,it's not working.I have same problem.
public void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
Upvotes: 0
Views: 1039
Reputation: 1170
I had the same problem. The solution is that you must draw your new picture in another bitmap and when it completes, draw it in your picturebox.
Upvotes: 0
Reputation: 3810
The way you are drawing, you are using the GDI to draw the pictures (basically using software to render game graphics). This is going to be slow compared to normal games, because most games use DirectX or OpenGL to blit the data to the video card very fast at the hardware level. I would recommend learning Microsoft XNA and writing your game in XNA, which is based upon C# and offers a nice content pipeline to do exactly what you are wanting to do.
Upvotes: 1