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);
}
Related
I can't get out from my problem.
I have a panel with multiple controls and I want them be as large as the panel width.
These controls can be extended and collapsed by a clicking a button, showing or not some controls they contain.
So the I've set Dockstyle.Fill = true for the panel.
The problem is: when I click for extending one of this controls, the scroll bar is showed (and it's ok) but it automatically cause a resize of the width of the controls in the panel and it is really bad looking and slow, because I have a lot of controls!!!
I have tried adding Padding and Margin to the panel, but with no result.
I have tried making a first panel where to put the controls with a fixed width less 40px (more than the size of the scrollbar) and a fixed height with Dockstyle.Fill = false and then putting this first panel inside a parent panel with Dockstyle.Fill = true, but with no result. The scrollbar doesn't show itself when I click for extending one control.
The following one should work (i'm working on it):
the panel should have Dockstyle.Fill = none and when I click to extend or collpase the control I should also adjust the height of the panel (panel's height = heights' sum of all elements visibile in the panel)
I've already seen similar questions but still could not get it to work
I have the following controls on my Form (refer image):
A: a groupbox
B: another groupbox
C: a panel which contains A and B
Height of the panel is adjusted on window resize. I have tried using Autoscroll = true on the panel but the scrollbars won't show.
The groupbox A is anchored to Top Left and has dock Top. The groupbox B is anchored to Top Leftbut has dockFill`.
Any idea why the scrollbar isn't showing ?? Also, What dock property should I give to new controls ( groupbox, maybe ), if I plan on adding more of them. I would want to show them one below the other.
Make your GroupBoxes To dock Top both. and turn autoscroll on true for your panel. That way they will stack on each other expanding themselfs down and ignoring the panel height. Also set a minheight and minwidth for both so if the panel gets to small it will start so overflow and show the scrollbars.
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.
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;
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.