[C#]Flickering screen when Drawing

DrEvil

FCRI Associate!
Reaction score
111
Hey i've been working on something in C#
And when I use Graphic.DrawImage(...) it starts to flicker XD
Do you know what causes it to flicker ? And a fix of any sort ?
Thanks :D
 

Samael88

Evil always finds a way
Reaction score
181
How have you built your program?

I think that you need to use buffering if you are are not doing it already.
You basically got a "image" where you draw everything on and when you are finished drawing you flip it out to the screen.

Like this:

image screen;

apply_object(test, screen);
flip/show(screen);

get me?

Edit: btw, if you are using buffering already perhaps you should use double buffering, here is an explanation:
http://en.wikipedia.org/wiki/Double_buffering
 

DrEvil

FCRI Associate!
Reaction score
111
Thank you , I fixed my problem with the following code :

Code:
protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            g.Clear(Color.Black);
            ...

            CurMap.Draw(g, this);
            ...

            base.OnPaint(e);
        }

private void Init()
{
...
this.SetStyle(ControlStyles.UserPaint |
              ControlStyles.AllPaintingInWmPaint |
              ControlStyles.ResizeRedraw |
              ControlStyles.ContainerControl |
              ControlStyles.OptimizedDoubleBuffer,true);
...

}

One last question :D

What does the base.OnPaint(e); do ?
 

Samael88

Evil always finds a way
Reaction score
181
I am guessing a bit here with the name and all, but I think it has to do with when you paint, as it seems it is almost as a "OnEvent()" or event handling function.
It probably take an event if the mouse button is down and draw the current selected color there.

Not sure tho, the first part I am certain about.
 

DrEvil

FCRI Associate!
Reaction score
111
ah ok , so them overide methods can be stopped ( if not needed ) just by removing the base.On...() ?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top