GDI+ : DoubleBuffer makes makes my program slower!!

GDI+ : DoubleBuffer makes makes my program slower!!

Post by hstagn » Thu, 26 Jul 2007 23:59:48


I am to code C#... and I am trying to make a ball moving at the screen.
(Actually I aws trying to make a pong but first I want to make a ball
moving at screen)

I did it and it worked well, but the ball is blinking while moving. I
tried to put the following lines os code inside my Form's constructor:

/**************TESTING...Double buffer********************/
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
/********************************************************/
Now, my ball does not blink but the animation is too much slower. I
will show you my code, so that you can test it WITH and WITHOUT the
above lines. Can you help me ?
(I heard about overriding the onPaintBackground method but it didnt
work either)
/*************************START HERE*************************/
using System;
using System.Windows.Forms;
using System.Drawing;

class Ball
{


public int xPos, yPos;
int xVet, yVet;
public Color currColor;
public Ball(int xIniPos, int yIniPos)
{
this.xPos = xIniPos;
this.yPos = xIniPos;
this.xVet = 1;
this.yVet = 3;

currColor = Color.Red;


}


public void NextPositionAndVector()
{
xPos += xVet;
yPos += yVet;


if (yPos<=0 || yPos>=500){
yVet = -yVet;
}
if (xPos<=0 || xPos>=500)
xVet = -xVet;



}
}




public class MainForm : Form
{


Timer ballTimer = new Timer();
Ball myBall = new Ball(100, 100);


public MainForm(){


this.Bounds = Screen.PrimaryScreen.Bounds;
this.ResumeLayout(true);
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
Cursor.Hide();
this.BackColor = Color.Black;



ballTimer.Interval = 1;

/**************TESTING...Double buffer********************/
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
/********************************************************/

this.Show();
this.KeyDown += new KeyEventHandler(MainFormKeyDown);
ballTimer.Tick += new EventHandler(ballTimer_OnTick);
ballTimer.Start();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.FillEllipse(new SolidBrush(myBall.currColor), myBall.xPos,
myBall.yPos, 40, 40);

}


// protected override void OnPaintBackground(PaintEventArgs e)
// {
// }


public void ballTimer_OnTick(object Sender, EventArgs e)
{

myBall.NextPositionAndVector();
this.Invalidate();

}

public void MainFormKeyDown(object Sender, KeyEventArgs e)
{
this.Close();

}


}


public class App
{

public static void Main(){
Application.Run(new MainForm());
}

}
/
**********************************************************************/
 
 
 

1. GiST -- making my index faster makes is slower

2. What makes laptops get slower and slower?

Or desktops for that matter.

I have a Toshiba PIII with 256 megs, running 98se. When
I got it 2 years ago it was SCREAMING fast. It's now
slower than slow, even though I've stripped almost ALL the
stuff off the hard drive (11 gigs free out of 20), I've defragged,
run Norton Optimize, and all that. And yet it's still slower than
it ought to be. I've noticed this before on desktops too.

Does 98 slowly degrade through some process of corrupting
itself?

I'm sure some wiz has tried to figure this out - I'm not unique
in this experience...

JOE

3. macros making files slower and slower

4. What makes laptops get slower and slower?

5. Making VFP8 main program invisible in applications without making forms invisible?

6. GDI+ error when trying to use DoubleBuffer

7. DoubleBuffer in GDI+

8. gdi+ DoubleBuffer causes double clearing

9. @ local variable makes query slower?

10. SP3 has made my WindowsXP *much* slower

11. Challenge for Desault who makes Solidworks, prove it, as I see it slower, not faster.

12. SET NOCOUNT ON makes execution SLOWER....

13. blackberry sync making Outlook slower

14. Variable makes query 10x slower

15. Switches made things slower