Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mike

Custom C# Control Flicker...

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m developing my own programming window (like that which you program in when using VS .Net); however, it flickers something awful when the window is redrawn (each time the user presses a key on the keyboard). Any ideas on how I can reduce flicker? I''ve set the style of the control to doublebuffered. But I don''t know what to do beyond that in the .Net envoronment. In C++ I would just use the Win32 API to create an offscreen buffer that Iwould draw to then copy and paste from there. This would prevent flicker, but I don''t know what to do in .Net to help prevent this flicker. Thanks for any help, Mike

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
override OnPaintBackground.

http://staff.develop.com/candera/weblog2/articleview.aspx/WinForms/FlickerFree.xml

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
With Windows Forms you can enable double buffering with custom controls which I found removed all the flicker. I don''t have the code at hand right now due to being at work. But it shouldnt be that difficult to find now you know what to look for.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
With Windows Forms you can enable double buffering with custom controls which I found removed all the flicker.

He already said he tried that.

However, he didn''t say that he set the AllPaintingInWmPaint flag...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
SetStyle( ControlStyles.AllPaintingInWmPaint, true );
SetStyle( ControlStyles.DoubleBuffer, true );

always worked for me.

Share this post


Link to post
Share on other sites
okay, this is odd, when i use:

SetStyle( ControlStyles.AllPaintingInWmPaint, true );

the result is an entirely black window. I have no idea why. the drawing works fine unless I set that flag. Any ideas? With AllPaintingInWmPaint sent, the window is entirely black until you press a key. when you press the key, it flickers for a moment (durring that flicker it is properly drawn), the goes back to being all black. All of the code for my window''s drawing resides in OnPaint event handler.

Any ideas?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What happens if you use delegates?

Constructor:
Paint += new PaintEventHandler(PaintProc);

This is the kind of code generated by VS.NET when asking to handle the Paint event, it doesn''t override OnPaint.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster This is the kind of code generated by VS.NET when asking to handle the Paint event, it doesn''t override OnPaint.

Overriding OnPaint is the recommended way if you are deriving from Form. However, you are required to call base.OnPaint().


--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites
Okay, I've developed my own OnPaint handler, now I'm having an interesting problem. Here is my OnPaint


protected override void OnPaint( PaintEventArgs e )
{
base.OnPaint( e );

Console.Write( "OnPaint\n" );
FillEmptySpace();
DrawText( true );
DrawLineNumbers();
DrawBorders();
}


and here is the constructor


public iCoderTextBox()
{
this.SetStyle( ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.Opaque |
ControlStyles.AllPaintingInWmPaint , true );

// This call is required by the Windows.Forms Form Designer.

InitializeComponent();
// TODO: Add any initialization after the InitForm call

m_bBorderColor = new SolidBrush( Color.FromArgb( 0, 89, 16 ) );
m_bNumColColor = new SolidBrush( Color.FromArgb( 221, 255, 227 ) );
m_bCodeColColor = new SolidBrush( Color.White );
m_bSelLineColor = new SolidBrush( Color.FromArgb( 243, 243, 243 ) );
m_bCodeFontColor = new SolidBrush( Color.FromArgb( 0, 0, 0 ) );
m_bNumFontColor = new SolidBrush( Color.FromArgb( 0, 89, 16 ) );

m_iFontHeight = m_font.Height;

m_lnManager.LoadLanguageFile( "cpp.xml" );
m_hlManager.LoadLanguageFile( "cpp.xml" );

m_kbHandler = new KeyboardHandler( this );

m_lnManager.NewLine();
}


Here is how it looks without ControlStyles.AllPaintingInWmPaint set to true:
good

Here is how it looks with that style set
bad

[edited by - Mike on April 6, 2004 7:02:23 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!