我想设置splitterdistance移动的最小和最大距离...如何设置...我尝试使用panelMinSize它没有工作...
实际上在分配器的一个面板中我有一个控制器,分配器应该根据控制器进行调整。
答案 0 :(得分:5)
如果您不使用FixedPanel,请使用panel1和panel2的 MinSize
。
说, Panel1MinSize = 20
和panel2MinSize = 50
答案 1 :(得分:3)
您可以在InitializeComponent();
SplitterDistance
设置为控件的宽度(假设您有一个垂直拆分容器,如果您有一个水平拆分容器则使用高度)
然后您可以附加到SplitterMoved
事件,并确保SplitterDistance
大于控件宽度。
例如:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SplitterDistanceTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
splitContainer1.SplitterDistance = groupBox1.Width;
splitContainer1.SplitterMoved += new SplitterEventHandler(splitContainer1_SplitterMoved);
}
void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
{
ResizeSplitterDistance();
}
private const int MAXIMUM_SIZE = 200;
private void ResizeSplitterDistance()
{
if (splitContainer1.SplitterDistance < groupBox1.Width)
{
splitContainer1.SplitterDistance = groupBox1.Width;
}
if (splitContainer1.SplitterDistance > MAXIMUM_SIZE)
{
splitContainer1.SplitterDistance = MAXIMUM_SIZE;
}
// You could also do max/min percentages. Ive shown this below
// but commented out
/*int minimum_percent = 30;
int minimum_size = (int)((minimum_percent / 100m) * (decimal)splitContainer1.Width);
int maximum_percent = 50;
int maximum_size = (int)((maximum_percent / 100m) * (decimal)splitContainer1.Width);
if (splitContainer1.SplitterDistance < minimum_size)
{
splitContainer1.SplitterDistance = minimum_size;
}
if (splitContainer1.SplitterDistance > maximum_size)
{
splitContainer1.SplitterDistance = maximum_size;
}*/
}
}
}