How to apply a double buffer in a C# panel?

dxfoo

Newcomer
Joined
Sep 15, 2005
Messages
4
Location
Salem, OR
I guess the question says it all. Thanks in advanced.

Code:
        private void pnl_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics; 

            int[,] map = PC.currentMap;

            // Draw map.
            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    g.DrawImage(Images.imgGrass_1, x * 50, y * 50);
                }
            } 

            // Draw player.
            g.DrawImage(Images.imgC1_Stand, PC.X, PC.Y); 

            Refresh();  // or should i use invalidate? 
        }
 
Yeh, check out the link.

Also, you shouldn't have to refresh or invalidate at the end of your paint function...that would most likely erase all that you've drawn.
You need to add your function to the paint eventhandler of the control.
 
Back
Top