防止SplitContainer的容器调整大小时更改位置 [英] Prevent SplitContainer from changing location when its container resizes

查看:639
本文介绍了防止SplitContainer的容器调整大小时更改位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当调整控件/窗体的大小时如何保持SplitContainer.SplitterDistance不变,同时仍然允许用户手动调整它的大小?

How do I keep SplitContainer.SplitterDistance from changing when the control/form its in is resized while still alowing the user to manually resize it?

推荐答案

一种方法要做的就是让一个类变量独立地保持拆分器的当前位置,并带有一个标志来指示鼠标按钮是否按下:
One way to do it is to have a class variable to independantly hold the current position of the splitter and a flag to indicate if the mouse button is down:
int split_distance = 150;
bool mouse_down = false;


然后将以下事件处理程序添加到拆分容器中:


Then add the following event handlers to the split container:

private void splitContainer1_Layout ( object sender, LayoutEventArgs e )
{
     this.splitContainer1.SplitterDistance = this.split_distance;
}

private void splitContainer1_MouseDown ( object sender, MouseEventArgs e )
{
     this.mouse_down = true;
}

private void splitContainer1_MouseUp ( object sender, MouseEventArgs e )
{
      this.mouse_down = false;
}

private void splitContainer1_SplitterMoving ( object sender, SplitterCancelEventArgs e )
{
       if ( this.mouse_down )
       {
           this.split_distance = e.SplitX;
       }
}


FixedPanel属性允许将一个面板设置为在调整SplittContainer的大小时不更改其大小.
The FixedPanel property allows setting one panel not to change size when the SplittContainer is resized.


这篇关于防止SplitContainer的容器调整大小时更改位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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