Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Drawing with c# - smoothly

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Oct 15, 2009 6:38 am    Post subject: Drawing with c# - smoothly Reply with quote

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
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Thu Oct 15, 2009 7:56 am    Post subject: Re: Drawing with c# - smoothly Reply with quote

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
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Thu Oct 15, 2009 10:06 am    Post subject: Re: Drawing with c# - smoothly Reply with quote

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
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Oct 15, 2009 11:52 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Fri Oct 16, 2009 3:13 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Fri Oct 16, 2009 7:23 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Oct 16, 2009 4:23 pm    Post subject: Reply with quote

something is wrong then, since you shouldn't be flickering if you're double buffering.

you can also try handling WM_ERASEBKRND
http://msdn.microsoft.com/en-us/library/ms648055%28VS.85%29.aspx
Back to top
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Sat Oct 17, 2009 9:30 am    Post subject: Reply with quote


_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren
Back to top
View user's profile Send private message MSN Messenger
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Sat Oct 17, 2009 5:44 pm    Post subject: Reply with quote

Finally it is solved with double buffering. Thanks alot everyone Smile
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites