Can't programmatically set position of splitter

4 posts, 0 answers
  1. Gibran
    Gibran avatar
    5 posts
    Member since:
    Feb 2015

    Posted 12 Aug 2015 Link to this post

    Hello,

    I have a Windows Form application with a Telerik splitter. I would like to put a limit on how much the splitter can be dragged up. I've been searching high and low for a solution to this problem and I can't find anything. The closest I've come is this site here: http://www.telerik.com/forums/programmatically-setting-size

    It recommends setting the AbsoluteSize of one of the SplitPanels. So I set up a moving event handler and did this:

      private void radSplitContainerMain_SplitterMoving(object sender, SplitterCancelEventArgs e)
    {
    RadSplitContainer splitContainer = (RadSplitContainer)sender;

    if (splitter.Location.Y < 420
    && splitter.Location.Y > 0)
    {
    splitContainer.SplitPanels["splitPanelMainChart"].SizeInfo.AbsoluteSize = new Size(
    splitContainer.SplitPanels["splitPanelMainChart"].SizeInfo.AbsoluteSize.Width, 100);
    }
    }

    This doesn't do anything though. I am still able to drag the splitter way below 420 and it doesn't seem to reposition it.

    Can anyway help me out?

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 13 Aug 2015 Link to this post

    Hi Gibran,

    Thank you for writing.

    This is the correct way to move the splitter. However, you should use the SplitterMoved event instead of SplitterMoving. The attached video shows how this works on my side (if the splitter is moved in the top part the panel height will be set to 20, if it is dropped in the bottom it will remain there). I used the following code:
    void radSplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
    {
        RadSplitContainer splitContainer = (RadSplitContainer)sender;
     
        if (splitContainer.Splitters[0].Location.Y < 420 && splitContainer.Splitters[0].Location.Y > 0)
        {
            splitContainer.SplitPanels[0].SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Absolute;
            splitContainer.SplitPanels[0].SizeInfo.AbsoluteSize = new Size(0, 20);
        }
    }

    I hope this helps. Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Gibran
    Gibran avatar
    5 posts
    Member since:
    Feb 2015

    Posted 13 Aug 2015 Link to this post

    Thanks Dimitar,

    This works. However, as you will notice, I'm also trying to allow the splitter to totally collapse, hence the check for Location.Y > 0.

    This is not working. The Y value for when I drag the splitter all the way up, or when I double click on it, is inconsistent. Sometimes it's 202, other times it's 222, and other times it's 413.

    Any idea what's going on here?

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 14 Aug 2015 Link to this post

    Hi Gibran,

    Thank you for writing back.

    It appears that it is unnecessary to check if the value is bigger that zero (it will always be bigger). If you want to totally collapse the panel when specific size is reached, you can rewrite the code like this:
    void radSplitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
    {
        RadSplitContainer splitContainer = (RadSplitContainer)sender;
         
        if (splitContainer.Splitters[0].Location.Y < 420 && splitContainer.Splitters[0].Location.Y > 20)
        {
            splitContainer.SplitPanels[0].SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Absolute;
            splitContainer.SplitPanels[0].SizeInfo.AbsoluteSize = new Size(0, 20);
        }
        else if (splitContainer.Splitters[0].Location.Y < 20)
        {
            splitContainer.SplitPanels[0].SizeInfo.SizeMode = Telerik.WinControls.UI.Docking.SplitPanelSizeMode.Absolute;
            splitContainer.SplitPanels[0].SizeInfo.AbsoluteSize = new Size(0, 1);
        }
    }

    I hope this information helps. 

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top