I have a .net app that I\'ve written in c#. On some forms I frequent update the display fields. In some cases every field on the form (textboxes, labels, picturebox, etc) ha
i had the same problem with OpenGLES, which is how i found this thread. of course i realize u are not using ogl, but maybe this helps u anyway ;)
protected override void OnPaintBackground(PaintEventArgs e)
{
}
You didn't research this well. There is a DoubleBuffered property in every Form. Try setting that to true. If you havn't overloaded anything on the form painting, then everything should work.
You could try to call this.SuspendLayout(); before you start your update and this.ResumeLayout(false); when you have finished setting all the values in this way it should prevent the form from writing values one at a time.
I know this question is old, but may be it will others searching for it in the future.
DoubleBuffering doesn't always work well. To force the form to never flicker at all (but sometimes causes drawing issues):
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; //WS_EX_COMPOSITED
return cp;
}
}
To stop flickering when a user resizes a form, but without messing up the drawing of controls (provided your form name is "Form1"):
int intOriginalExStyle = -1;
bool bEnableAntiFlicker = true;
public Form1()
{
ToggleAntiFlicker(false);
InitializeComponent();
this.ResizeBegin += new EventHandler(Form1_ResizeBegin);
this.ResizeEnd += new EventHandler(Form1_ResizeEnd);
}
protected override CreateParams CreateParams
{
get
{
if (intOriginalExStyle == -1)
{
intOriginalExStyle = base.CreateParams.ExStyle;
}
CreateParams cp = base.CreateParams;
if (bEnableAntiFlicker)
{
cp.ExStyle |= 0x02000000; //WS_EX_COMPOSITED
}
else
{
cp.ExStyle = intOriginalExStyle;
}
return cp;
}
}
private void Form1_ResizeBegin(object sender, EventArgs e)
{
ToggleAntiFlicker(true);
}
private void Form1_ResizeEnd(object sender, EventArgs e)
{
ToggleAntiFlicker(false);
}
private void ToggleAntiFlicker(bool Enable)
{
bEnableAntiFlicker = Enable;
//hacky, but works
this.MaximizeBox = true;
}
It could also be caused by your coding, not the absence of doublebuffering. I came here just now with a similar problem but realised it's because:
In other words:
So what's the solution? How to avoid thousands of needless ListView.SelectedIndexChanged events?
This worked for me.
http://www.syncfusion.com/faq/windowsforms/search/558.aspx
Basically it involves deriving from the desired control and setting the following styles.
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);