Reputation: 2914
I'm having the following code to set the width of the first panel to the width I need (for some reason I need to divide the expectedWith by two to get the actual width to be my expectedWith - don't know why).
splitContainer1.SplitterDistance = expectedWith / 2;
The next thing I need is that the first panel is fixed, means that if you resize the window, only the second panel gets larger and the first stays in size. To achieve this I use the following line:
splitContainer1.FixedPanel = FixedPanel.Panel1;
Problem now: it seems that the FixedPanel-property completly ignores the size of the first panel. It doesn't matter which value I set the SplitterDistance-property to if I used the FixedPanel-line. It is always the same. It doesn't even matter if I set SplitterDistance in the form designer.
Is there a solution to this?
Upvotes: 4
Views: 2797
Reputation: 2794
In my particular case I was observing the same thing: SplitterDistance
works as long as FixedPanel
is not set but the fix was ensuring .Size
is set to a value bigger than .SplitterDistance
before setting it:
splitContainer.Size = new System.Drawing.Size(1000, 1000); // !!!
splitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
splitContainer.SplitterDistance = 400;
Upvotes: 0
Reputation: 91
I've figured this out. I needed to have a page open and load the splitter positions from the registry but was very frustrated with the way the watch I set up showed that it kept going back to the design time setting of the control.
To fix it all you do is change the property of "FixedPanel" from "None" to panel1 or panel2. Which is up to you. it only really comes into play when the minimum setting is not small enough and/ or when you have a splitcontainer within another sizable container. the fixed panel stays fixed then. Both panels can be resized as you choose using a mouse though so the word fixed is a little ambiguous in that regard.
so take the design time control. drop it on the form. resize it to fit your requirement and anchor it as necessary. nothing else except making one of the panels fixed. There is a property called "IsSplitterFixed" don't touch it, it's one of the reasons this control becomes unstable and must stay false, the panel.minsize properties should be set at design time based on requirements and you will always have to take cognisance of their values.
live happily ever after!
Upvotes: 0
Reputation: 1695
I ran into this same problem, and was tempted to use the original poster's advice and just divide the desired SplitterDistance by two, as it always seemed to be (nearly but not exactly) twice the width that I asked for.
I tried changing the DockStyle of the children of the two panels to None before setting the SplitterDistance, but in my case it did not have any impact on the problem.
I solved the problem by changing when the SplitterDistance gets set. Originally I was setting the SplitterDistance on the panel before calling Form.Show(). Setting the SplitterDistance after the form is shown seemed to cure it.
Upvotes: 1
Reputation: 41
The DockStyle.None
is a step in the right direction. But it needs 3-6 iterations (shaking the Splitter), until the Panel-Window has the expected dimensions. Strange!
Upvotes: 0
Reputation: 686
Since you only want a fixed first panel and a dynamic second one, couldn't you use a TableLayoutPanel instead of a SplitContainer?
Upvotes: 0
Reputation: 2914
I can answer my own question. This only happens if the content of the appropriate panel is using DockStyle.Fill in its Dock-property. The solution is to set the DockStyle.Fill value right after setting FixedPanel. This was also responsible for the "divide by two"-behaviour explained in the question.
Thanks to John Willemse.
Upvotes: 5