Moving form objects around

  • Thread starter Thread starter chris.dannemiller
  • Start date Start date
C

chris.dannemiller

I need to be able to move a few form abouts around after a event occurs
but when I do this it causes massive flickering is there any way to
reduce this?
 
Hi

Checkout the SuspendLayout and ResumeLayout methods.

Also, what event are you talking about? It really depends how often you
want your form to draw. Every pixel of the movement? Only when it gets
to its destination?

Cheers,
Steven Nagy
 
Thanks for the suggestion but I am still seeing the flickering. Its
button that the user clicks that causes the form layout to require a
change.
 
Stick your code on here for the button event (just the important stuff)
and also try to answer some of my other questions. We'll get you
sorted!
 
private void Form_Resize(object sender, System.EventArgs e)
{
SuspendLayout();
// Panel1, and Custom1 are aligned top left as well.
// Panel1 surrounds Custom1 + 1 Pix this is implied below.
// Custom 1 uses GDI+ and has a Scroll bar that may or may not be
visible on the
// right side
// CustomTo*Edge calculated at load time distance from the * to the
Edge of the form.
Custom1.SuspendLayout();
// Keep this constant.
Custom1.Width = ClientRectangle.Width - Custom1.Left -
CustomToRightEdge;
Custom1.Height = ClientRectangle.Height - Custom1.Top -
CustomToBottomEdge;
// Recalculate and .Value member of the scroll bar so the user does
not get confused.
Custom1.RecalcScrollBar ();
panel1.Width = ClientRectangle.Width - panel1.Left - CustomToRightEdge
+ 2;
panel1.Height = ClientRectangle.Height - panel1.Top -
CustomToBottomEdge + 2;
leadsControl1.Invalidate();
leadsControl1.ResumeLayout(true); // If false scroll bar does not
move
ResumeLayout(false);
}

There is also a Custom control that is docked to the left side but it
does not flicker. And a label1 that is aligned to Top, Left that
requires no more complex logic, again it does not flicker. Flickering
is most apparent when resizing along the left edge of the Form.

It is possible to collapse panel1 and custom1 into one control, but it
would require calculating where the scroll bar is. The panel simply
draws a black box around custom1. I have also tried the WM_SETREDRAW
workaround however there is bleeding from what is behind the form while
the user is resizing, but the flicker is gone.
 
I just figured out that most of the logic above save the recalc scroll
bar and invalidate can be avoided by simply aligning to all edges
however this does not solve the problem of flickering. But it helped
 
Whats generally happening in the RecalcScrollBar method? Are you also
invalidating the control in there?
 
Back
Top