SplitContainer - Fixed Panel Height on Resize - c#

every time I resize my form, panel2 get bigger, I want panel1 to get bigger and panel2's height to stay the same unless the user changes the splitterdistance themselves.

Try setting the FixedPanel property:
splitContainer1.FixedPanel = FixedPanel.Panel2;

Related

SplitterDistance changes as size of control changes

I have a SplitContainer control on my form. It's docked to the form. And I set the SplitterDistance from code when the form loads.
This works fine except that the SplitterDistance changes when I resize the form. For example, when I make the form wider, the SplitterDistances seems to become larger so that it retains about the same percentage of width of the parent.
I don't want this. I want the distance between the splitter bar and the left of the control to stay the same as the window is resized. However, I don't want to set IsSplitterFixed = true because I still want to allow the user to change it.
You can set FixedPanel property to the panel which you want to remain the same size when the container is resized. You can do it using designer, or using code:
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;

Winforms Panel Size

In my form I have a panel with autosize = true.
The panel contains a SplitContainer control with 2 panels arranged horizontally.
The top panel contains a datagridview and the bottom panel contains a textbox.
Is there a way I can programmatically resize the top panel, and hence the entire SplitContainer based on changes in the height of the datagridview (determined by the number of rows)
UPDATE:
I am now able to resize the SplitContainer which has Dock = Bottom, however, the Layout event of the parent panel does not get fired in response to changes in the height of the SplitContainer control even thought the parent panel has Autosize = True
Try setting the splitter distance of the SplitContainer based on the height of the grid.
SplitterDistance Gets or sets the location of the splitter, in pixels, from the left or top edge of the SplitContainer.
Via https://msdn.microsoft.com/en-us/library/system.windows.forms.splitcontainer.splitterdistance(v=vs.110).aspx
Edit
What worked for me was to set Dock for the SplitContainer to None, which then allowed me to set the size of the SplitContainer (calling SplitContainer.Height) and having the panel resize itself to fit the SplitContainer.
Edit 2
To allow the SplitContainer to auto-size its width, you can try the following:
splitContainer.Width = this.ClientRectangle.Width - (splitContainer.Location.X * 2)
This.ClientRectangle.Width should get the width of the window without the border (if the parent is the form).
For some reason that I dont manage to understand, if I force the panel size in the code the object gets the right size.
If I define the panel size 300x300 in the IDE, later is shown smaller and the lines are not visible.
public Form1()
{
InitializeComponent();
panel1.Size = new Size(300, 300);
}

How to make a panel centered with minimum and maximum width in Visual WebGUI?

I would like to make a panel with this behaviour in Visual WebGUI.
if window's width is smaller than minimal width of the panel, scrollbar appears.
if window's width is bigger than minimal width of the panel, the panel fill the width of the window.
if window's width is bigger than maximal width of the panel, panel remains at maximal width and sides of the window are empty.
Panel needs to be always in the center of the window.
How can I achieve that ? Thank you
Create a panel.
Set the Dock = Fill for the panel.
Set the MinimumSize property of the panel to your desired width and height.
Now put any controls inside the panel. But set the controls anchor property to None.
This way your controls will always be centered and scrollbars will be visible as you desired.

How to prevent changing picturebox's size when changing size of the control that contains the picturebox?

I have a user control with picturebox on it. I want the picturebox size to remain the same, but the form that contains the user control changes the hight of the control and the picturebox's height changes. Can I somehow keep the height (and width) constant?
If the picture box is docked or has anchors set, it "follows" the parent's height (and width, if the correct anchor/docking is configured).
Please check whether you set the Dock and Anchor properties correctly. See also this tutorial.

Scrollbar does not appear on Panel when lines drawn on it (C#)

I want to draw some lines and rectangles on a panel. Sometimes it does not fit in panel
and I want the scroll bar to appear. I set AutoScroll property to true, but it doesn't work ;(
Set the panel's AutoScrollMinSize property to a something larger than the panel's real dimensions (for example, if your panel is 300 x 200, set the AutoScrollMinSize property to 900 x 600). This will cause both scrollbars to appear, and you should be able to draw on the larger surface.
You will need to tell the panel control that you are drawing outside of the visible bounds by setting the AutoScrollMinSize property. But another, perhaps simpler, solution would be to have your panel contain another panel control in which you do the drawing. Then you can simply resize that inner panel to fit your drawing and the outer panel will automatically provide the scrolling as necessary.

Categories

Resources