在拆分器移动时刷新 SplitContainer 的面板 [英] Refresh the panels of a SplitContainer as the splitter moves

查看:17
本文介绍了在拆分器移动时刷新 SplitContainer 的面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个面板的 SplitContainer.当我拖动拆分器来调整两个面板的大小时,我在拖动时看到一个灰色条.在我松开鼠标按钮之前,面板实际上不会重新绘制.如何让面板在拖动拆分器时刷新?

I have a SplitContainer with two panels. When I drag the splitter to resize the two panels, I see a grayish bar as I'm dragging. The panels don't actually get redrawn until I release the mouse button. How can I make the panels refresh as I drag the splitter?

Fwiw,这是在 Delphi 中通过将 Splitter 控件的ResizeStyle"设置为rsUpdate"来实现的.

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

我尝试将以下代码放入 SplitterMoving 事件中,但没有明显的变化.

I have tried putting the following code inside the SplitterMoving event with no visible changes.

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

推荐答案

您可以尝试使用详细的鼠标事件在本页:

You could try using mouse events as detailed in this page:

    //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;
            }
        }
    }

这篇关于在拆分器移动时刷新 SplitContainer 的面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆