Flicker Free Drawing in C#
-
In your constructor (of the control that is drawn upon):
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint);
Did this from the top of my head, so maybe the enums are not spelled correctly, but it should point you in the right direction. Also make sure you do the painting in
OnPaint
, notGreateGraphics
. HTH! :)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
In your constructor (of the control that is drawn upon):
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint);
Did this from the top of my head, so maybe the enums are not spelled correctly, but it should point you in the right direction. Also make sure you do the painting in
OnPaint
, notGreateGraphics
. HTH! :)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
Hi Marc, Thanks for the suggestion but i am using a RichtextBox and it does not has a setStyle method any other suggestions will be appreciated Waiting for your quick reply. Thanks Pramod
RichTextBox
does have aSetStyle
method (it is inherited fromControl
), but it is protected so only accessible from a derived class. As was suggested above, to get the functionality you require you must inherit fromRichTextBox
, set the relevant style flags in your constructor and do your painting in the overridenOnPaint
method. Im pretty sure you are usingGraphics g = Graphics.CreateGraphics(yourRTBInstance)
to draw, which in this case is the wrong way. -- modified at 8:29 Wednesday 11th January, 2006 -
RichTextBox
does have aSetStyle
method (it is inherited fromControl
), but it is protected so only accessible from a derived class. As was suggested above, to get the functionality you require you must inherit fromRichTextBox
, set the relevant style flags in your constructor and do your painting in the overridenOnPaint
method. Im pretty sure you are usingGraphics g = Graphics.CreateGraphics(yourRTBInstance)
to draw, which in this case is the wrong way. -- modified at 8:29 Wednesday 11th January, 2006 -
Oh yeah it's protected, i had forgotten that :doh:
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
RichTextBox
does have aSetStyle
method (it is inherited fromControl
), but it is protected so only accessible from a derived class. As was suggested above, to get the functionality you require you must inherit fromRichTextBox
, set the relevant style flags in your constructor and do your painting in the overridenOnPaint
method. Im pretty sure you are usingGraphics g = Graphics.CreateGraphics(yourRTBInstance)
to draw, which in this case is the wrong way. -- modified at 8:29 Wednesday 11th January, 2006 -
Hi Marc, i got it and now the drawing is done fine but still some flickering is there. This has also caused one more problem\, Due to this code now if i type something in the Richtextbox it does not shows the text instead white spaces are shown any suggestions to avoid this Thanks
-
Hi Marc, i got it and now the drawing is done fine but still some flickering is there. This has also caused one more problem\, Due to this code now if i type something in the Richtextbox it does not shows the text instead white spaces are shown any suggestions to avoid this Thanks
I have no experience with RichTextBoxes, only owner-drawn controls, so i dont think i can help you that much. You can try fiddling with the SetStyle flags.
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
base.Setstyle(ControlStyles.DoubleBuffer, true);
or
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
or
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);Sorry i can't help you any further...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
I have no experience with RichTextBoxes, only owner-drawn controls, so i dont think i can help you that much. You can try fiddling with the SetStyle flags.
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
base.Setstyle(ControlStyles.DoubleBuffer, true);
or
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
or
base.Setstyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true);Sorry i can't help you any further...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
|| Fold With Us! || Pensieve || VG.Net ||
-
i tried all the options but none of them are working for me Anyways Thanks for the suggestions :) Pramod
Did you try this?
public class MyRichText : RichTextBox
{
public MyRichText()
{
//by setting Double Buffer, the painting will finish before its redenered
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.Selectable, true);} }
Jordan