Обновите панели SplitContainer по мере движения сплиттера - PullRequest
7 голосов
/ 29 июня 2011

У меня есть SplitContainer с двумя панелями.Когда я перетаскиваю разделитель, чтобы изменить размеры двух панелей, при перетаскивании я вижу серую полосу.Панели не перерисовываются, пока я не отпущу кнопку мыши.Как сделать так, чтобы панели обновлялись при перетаскивании сплиттера?

Кстати, это достигается в Delphi, если для параметра «ResizeStyle» элемента управления Splitter установить значение «rsUpdate».

Я попытался поместить следующий код в событие SplitterMoving без видимых изменений.

private void splitCont_SplitterMoving(object sender, SplitterCancelEventArgs e)
{
    splitCont.Invalidate();
    //also tried this:
    //splitCont.Refresh();
}

1 Ответ

17 голосов
/ 29 июня 2011

Вы можете попробовать использовать события мыши, как подробно на этой странице :

    //assign this to the SplitContainer's 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's 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's 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 (e.X > 0 && e.X < ((SplitContainer)sender).Width)
                    {
                        // Move the splitter & force a visual refresh
                        ((SplitContainer)sender).SplitterDistance = e.X;
                        ((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 (e.Y > 0 && e.Y < ((SplitContainer)sender).Height)
                    {
                        // Move the splitter & force a visual refresh
                        ((SplitContainer)sender).SplitterDistance = e.Y;
                        ((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;
            }
        }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...