Search code examples
c#.netwinformssplitter

splitcontainer splitterdistance for panel 2


I use Windows Forms SplitContainer. I want set the SplitterDistance value but for the Panel2 instead Panel1. Is it possible ?

When I set SplitterDistance, it sets the distance based on first panel, while I want to set the distance based on second panel.


Solution

  • Set the distance based on width or height of control.

    For example in a horizontal SplitterContainer when you want to set distance from bottom to 50, use such code:

    splitContainer1.SplitterDistance = splitContainer1.Height - splitContainer1.SplitterWidth 
                                       - 50;
    

    For a vertical SplitterContainer use width of control.