Custom C# Control Flicker...

Started by
15 comments, last by Mike 20 years ago
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
Advertisement
override OnPaintBackground.

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

thanks, that helped a ton.
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.
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...
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
SetStyle( ControlStyles.AllPaintingInWmPaint, true );
SetStyle( ControlStyles.DoubleBuffer, true );

always worked for me.
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?
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.
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]
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
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]

This topic is closed to new replies.

Advertisement