tags:

views:

82

answers:

2

I want to set the minimum and maximum distance for the splitterdistance to move around... how to set that... i tried using panelMinSize it didnt worked...

Actually in one of the panel of the splitter i have a control and the splitter should adjust based on the control..

A: 

If you don't use a FixedPanel, play with MinSize of panel1 and panel2.

Say, Panel1MinSize = 20 and panel2MinSize = 50

serhio
A: 

You could set the SplitContainer's SplitterDistance to the control's width (assuming you have a vertical split container, use the height if you have a horizontal split container) in the constructor after InitializeComponent();

Then you can attach to the SplitterMoved event and make sure the SplitterDistance is larger than the Controls width.

For example:

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