Auto resizing controls on full screen in windows forms - c#

I want to auto resize my windows form controls on fullscreen. I use tableLayoutPanel and anchoring.
But it's not pleasing to the eyes. I used flowLayoutPanel, but it doesn't work. I have around 35 controlrs on one single form, including labels, textboxes, comboboxex, radiobuttons, datagridview and checkbox.
Is there any other method by which I can resize the controls? And if not, can anybody suggest me a way to use the tableLayoutPanel and anchoring more effectively?

It seems to me that what you want to use is the Dock property of all controls as well as using TableLayoutPanel. From the images you provided it looks like you want want the top half of the form to be a TableLayoutPanel, and to set the Dock Property to DockStyles.Fill. Then set the bottom ListView to DockStyles.Bottom.
You can either dock each control in a TableLayoutPanel cell or set the Anchor properties to AnchorStyles.None to make the controls automatically be centered in the cells.

Related

How to dock datagridview to parent container but leave space for search fields?

I want to leave some space for search fields on the top of
datagridview but also want to dock my datagridview to parent
container, so when I open the application as maximize it should fit
the screen.
below are the images to explain you better.
If I dock the datagridview to parent container
if I undock datagridview and add search fields on the top of it (Without running application).
if I open the datagridview form in maximize form it looks like this.
I want to leave some space for search fields but dock the remaining
datagridview to maximize window. (When I run the app).
use two panels, one is Dock top and another Dock fill, place your grid in the second panel and make it also dock fill. You can apply dome padding for the grid by setting padding property in the second panel.

AutoScroll event in WIndows Forms

I have a windows form with two controls, one mail control (Dock = Fill) and a property control (Dock = Right). The property control is set to AutoScroll. It has some expandable panels and if the user expands too many panels the height of the control is larger than the window height and I set the AutoScroll property in order to automatically display scrollbars in this case - this does work. However the scrollbar is plotted over the property controls. The scrollbars of course needs some place but I would like the property window to grow in width as long as the scroll bar is shown (and hence reduce the size of the main control a bit) so that the scrollbar is on the right side of the property control which is completely shown.
Can you give me a hint? Do I need to change some properties of the controls? Or is there an Event "ScrollBarsShown" or something which I could catch and manually extend the width of the property control?
Thank you very much!
Put these controls in a TableLayoutPanel. The arrangement should be two columns, one row. Column0 would be set to 100%, while Column1 would be AutoSize. The Row could be either.
Then just dock fill the TableLayoutPanel in your form.

How do I make multiple controls in a Windows Form automatically resize with the window?

I'm new to Windows Forms in Visual Studio, and I am wondering how to automaticly resize controls to the window size.
Say, I have 2 controls in a panel, a List Box and a Button. I want the button to dock to the bottom, and I want the List Box to fit the rest of the space. when the window resizes, the button should be at the bottom (as expected with docking), and the list box should stretch down to the button.
Is there a way to do this without any code?
Thanks.
Dock is pretty easy to use, but I recommend using the Anchor properties instead. Resize your form to a reasonable size in the Designer. Then, place your controls to look the way you want. Then, decide which controls should resize with the form and set the Anchor property as follows:
If you want the control to resize with the form in width, set the Right anchor.
If you want to resize height, set the Bottom anchor.
If you want the control to stay right when the form resizes, unset the Left anchor.
If you want the control to stay bottom when the form resizes, unset the Top anchor.
The problem I have with Docks is that they sometimes act funny when controls are not declared in a specific order, and to get the effect you want, sometimes you have to create extraneous panels just to hold controls.
It really gets messy when you want to maintain the aspect ratio of each control. One way, which is not really up to the mark if you want to get into fixing the details, is to use TableLayoutPanel and use Dock and Anchor wisely to achieve what you want.
Use the dock and fill options on the controls. Look under properties for each object, and containers if they are in any.
You can use SplitContainer
Google for examples. Here is one
Try setting your ListBox's Dock property to Fill.
You'll need to watch for one thing though: by default the ListBox will size itself to display whole list items. If you resize the control so that it displays a partial item it will adjust itself so it will display a complete item. This can make the control appear to lose its 'Dock'ing behavior. The solution for this is to set the ListBox's IntegralHeight property to false, which specifies that the control not resize itself to fit complete items.

Make UserControl resize when Dock = Fill

I have a problem with UserControl that I'm crafting. It consists of TableLayoutPanel with another TableLayoutPanel in it with ListView inside. I want to make it resizable so that it will fit in left panel of my app and behave somewhat like Toolbox in Visual Studio. The problem is that my control doesn't scale when I resize panel.
UserControl is embedded in panel with Dock = Fill and Anchor = Tob, Left, Bottom, Right. Also all controls in it are made that way. How can I fix this?
EDIT: It's WinForms, not XAML.
Use a split panel and put your UserControl in the left panel and Dock.Fill it.
You're probably looking for the AutoSize properties on the TableLayoutPanel and the AutoSize ColumnType of that panel.
You can achieve something like a Dock = Fill by simply auto-sizing the table layout panel (GrowAndShrink) so that it will always fit your inner control.
Please post your designer code to see how you embedded the controls in which other control.
I suspect your resize problem come from your resizing strategy of control inside the TableLayoutPanel.
The table layout panel is tricky. Regarding the resize strategy you want to follow inside a cell of the table panel, the control in the cell have either to be Dock.Fill or Anchor = Top, Left, Bottom, Right.
Basically:
Il you want the grid cell to adapt to the size of the control, then have the control in the cell Anchor = Top, Left, Bottom, Right and set the row/column to autosize.
If you want the control in the cell to adapt to the cell size, use Dock.Fill on it and use a percentage or a absolute value to size your cell.
The behavior of the TableLayoutPanel is best described in the MSDN documentation.

c# resizing controls in splitcontainer

I have a splitcontainer with 2 panels. In the first panel is a Treeview and a Datagridview in the other.
When I move the splitter, to be able to see more of the treeview, the Datagridview gets 'pushed' out of the wind
You need to set the Dock property of the control in each pane to Full.
If you have multiple controls in a pane, you'll need to set their Dock or Anchor properties to achieve the behavior you want.
Minor point, but the dock style you want is Fill, not Full.

Categories