View previous topic :: View next topic |
Author |
Message |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Thu Oct 15, 2009 6:38 am Post subject: Drawing with c# - smoothly |
|
|
Code: | case DrawingMode.rectangle:
this.p.Refresh();
g.DrawRectangle(pen, new Rectangle(prevLoc.X, prevLoc.Y, offsetx, offsety));
break; |
How can I turn this into smooth drawing code. Refresh on mouse move makes it flicker ofc becuase it must redraw the shit too many times.
_________________
Intel over amd yes. |
|
Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Thu Oct 15, 2009 7:56 am Post subject: Re: Drawing with c# - smoothly |
|
|
JesusLovesQlimax wrote: | Code: | case DrawingMode.rectangle:
this.p.Refresh();
g.DrawRectangle(pen, new Rectangle(prevLoc.X, prevLoc.Y, offsetx, offsety));
break; |
How can I turn this into smooth drawing code. Refresh on mouse move makes it flicker ofc becuase it must redraw the shit too many times. |
Implementing double buffering should solve this problem. If you are drawing on the form itself, I think it's enough to set the DoubleBuffered property to true.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Oct 15, 2009 10:06 am Post subject: Re: Drawing with c# - smoothly |
|
|
JesusLovesQlimax wrote: | Code: | case DrawingMode.rectangle:
this.p.Refresh();
g.DrawRectangle(pen, new Rectangle(prevLoc.X, prevLoc.Y, offsetx, offsety));
break; |
How can I turn this into smooth drawing code. Refresh on mouse move makes it flicker ofc becuase it must redraw the shit too many times. |
There's a couple things you can do:
1. Handle WM_ERASEBKGND yourself and return TRUE, handle the redraw yourself.
2. Use double buffering. You get flickering because it's hard to make a change to a single buffer without ending up drawing only part of the image.
Pretty sure a memory DC is slow in GDI+, you should use the CachedBitmap class instead.
|
|
Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Thu Oct 15, 2009 11:52 am Post subject: |
|
|
the control doesn't have double buffer. I dont wanna draw directly on the form.
I would like to draw on a panel or a picturebox, preferably.
_________________
Intel over amd yes. |
|
Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Fri Oct 16, 2009 3:13 am Post subject: |
|
|
JesusLovesQlimax wrote: | the control doesn't have double buffer. I dont wanna draw directly on the form.
I would like to draw on a panel or a picturebox, preferably. |
Don't flicker, double buffer! Code: | class DoubleBufferedPictureBox : PictureBox
{
public DoubleBufferedPictureBox()
{
this.SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs pe)
{
DrawContent(pe.Graphics);
}
private void DrawContent(Graphics g)
{
// Paint your content here (This includes the control background)
}
} |
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Fri Oct 16, 2009 7:23 am Post subject: |
|
|
Odecey wrote: | JesusLovesQlimax wrote: | the control doesn't have double buffer. I dont wanna draw directly on the form.
I would like to draw on a panel or a picturebox, preferably. |
Don't flicker, double buffer! Code: | class DoubleBufferedPictureBox : PictureBox
{
public DoubleBufferedPictureBox()
{
this.SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs pe)
{
DrawContent(pe.Graphics);
}
private void DrawContent(Graphics g)
{
// Paint your content here (This includes the control background)
}
} |
|
Thanks.
edit :
OMG it didn't do a damn thing. It still flickers as much as it did before. AllPaintingInWmPaint even made it worse (the shapes just disaper).
_________________
Intel over amd yes. |
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
|
Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Sat Oct 17, 2009 9:30 am Post subject: |
|
|
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
|
Back to top |
|
 |
|