Refresh SplitContainer Panels When Moving Splitter

I have a SplitContainer with two panels. When I drag the splitter to resize the two panels, I see a grayish bar when I drag. The panels do not actually redraw until I release the mouse button. How to get panels to update as I drag the separator?

Fwiw, this is achieved in Delphi by setting the "ResizeStyle" of the Splitter control to "rsUpdate".

I tried to put the following code inside the SplitterMoving event without any visible changes.

private void splitCont_SplitterMoving(object sender, SplitterCancelEventArgs e) { splitCont.Invalidate(); //also tried this: //splitCont.Refresh(); } 
+4
source share
1 answer

You can try to use mouse events as detailed on this page :

  //assign this to the SplitContainer MouseDown event private void splitCont_MouseDown(object sender, MouseEventArgs e) { // This disables the normal move behavior ((SplitContainer)sender).IsSplitterFixed = true; } //assign this to the SplitContainer MouseUp event private void splitCont_MouseUp(object sender, MouseEventArgs e) { // This allows the splitter to be moved normally again ((SplitContainer)sender).IsSplitterFixed = false; } //assign this to the SplitContainer MouseMove event private void splitCont_MouseMove(object sender, MouseEventArgs e) { // Check to make sure the splitter won't be updated by the // normal move behavior also if (((SplitContainer)sender).IsSplitterFixed) { // Make sure that the button used to move the splitter // is the left mouse button if (e.Button.Equals(MouseButtons.Left)) { // Checks to see if the splitter is aligned Vertically if (((SplitContainer)sender).Orientation.Equals(Orientation.Vertical)) { // Only move the splitter if the mouse is within // the appropriate bounds if (eX > 0 && eX < ((SplitContainer)sender).Width) { // Move the splitter & force a visual refresh ((SplitContainer)sender).SplitterDistance = eX; ((SplitContainer)sender).Refresh(); } } // If it isn't aligned vertically then it must be // horizontal else { // Only move the splitter if the mouse is within // the appropriate bounds if (eY > 0 && eY < ((SplitContainer)sender).Height) { // Move the splitter & force a visual refresh ((SplitContainer)sender).SplitterDistance = eY; ((SplitContainer)sender).Refresh(); } } } // If a button other than left is pressed or no button // at all else { // This allows the splitter to be moved normally again ((SplitContainer)sender).IsSplitterFixed = false; } } } 
+10
source

All Articles