AutoScroll event in WIndows Forms - c#

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.

Related

How can I link a component's Size to the Window size?

I am making a simple WinForms program.
I would like to link a component's size to the size of the Window.
Let's say the user enlarges or shrinks the Window by dragging it's borders: I would like that a component gets bigger when the Window does and vice versa.
Let's pretend that we have two Buttons, in the center of the Window, side by side: I want to make them the same size filling the entire width of the Window.
How can I do that?
Sample procedure, using a TableLayoutPanel and 2 Buttons:
Add a TableLayoutPanel to the Form
Edit the Columns and Rows collections so that you have 2 Columns, both sized at 50% and one Row, set to Autosize.
Set the Location.X of the TableLayoutPanel to 0 and adjust its width to the width of the Form.
Set the TLP Anchor property to Left and Right
Adjust-drag the Row height to be ~twice the size of the Button it will host
Add one Button to the Form
Adjust the appearance of the Button as required.
CTRL-Drag the Button to create an exact duplicate
Add the two Buttons to the two cells of the TableLayoutPanel
SHIFT-Select both Buttons and set the Dock property to DockStyle.Fill
You can now adjust the Margin property of the Buttons (still both selected, so the same settings will apply to both) to modify the space between the controls
Re-adjust the TableLayoutPanel's only Row height as needed.
Extra: if you have only these controls on the Form, you may want to fix the MinimumSize of the Form, to avoid that, when the Form is resized, your controls are shrinked beyond recognition, ruining the overall layout: resize the Form in the Designer to a point where the hosted controls layout is compromised, find a suitable minimum size and use this measure as the Form's MinimumSize property. The MinimumSize can be set using only the Width or the Height measure (e.g., (100, 0)). This limits the Form's Width but not the Height. Or the opposite, of course.
If, when dragging the Buttons inside the TableLayoutPanel, the Buttons
are not automatically inserted at the Top-Left position of the cell
and instead they appear positioned in a random place, then the
TableLayoutPanel has gone rogue and needs to be put down. Delete it
and drop another on the Form. Rinse and repeat.
This may happen if you tamper with the layout a bit. Better start over than trying to correct the problem.
TableLayoutPanel Control Overview

How to reserve space in Win Form TableLayoutPanel control

I have a question about WinForm TableLayoutPanel control. For example, if I hide the control in the column. it will change the size.
Is there a way to not paint the control in a tablelayoutpanel with column autosize so that the column will still have the control size?
Using Control.Visible = false will make the column width 0.
I need something like hidden in WPF Grid.
You can place a Panel in the TLP and place the control on the panel. Set the panel's background color to the same as the TLP, and it will be invisible. Then hide the control but leave the panel.
This should work fine if your control is a fixed size. If the control size varies, it might be a bit more tricky to do this. You will need to vary the size of the Panel too. Setting it to AutoSize = true and AutoSizeMode = GrowOnly might work.

Auto resizing controls on full screen in windows forms

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.

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.

How can I organize controls on a form relative to one another and the form itself?

I have a child form in a MDI Windows Forms application. It has two controls: a ComboBox and a TreeView, with the last one under the first one. Both controls have the same width. How can I set up them and form properties to achieve the following:
When changing the size of the form, a width of both controls must be equal to the width of the form.
The height of the TreeView must be changing to fill all free space of the form.
You can do like this:
In the forms designer, layout the controls like you want them to look
Select the ComboBox, and set the Anchor property to Top, Left and Right
Select the TreeView and set the Anchor property to Top, Left, Right, and Bottom
Basically, you would need to dock your controls. Play with the Dock property of your both controls to find the "docking" which suits your requirements.
Here is an example which demonstrates a Combobox with Dock=Top and TreeView with Dock=Fill:
If you resize the form, the Combobox width and TreeView width/height will be resized accordingly, which suits your specific requirements.
This is done by the Anchor property. Set it properly on all controls (combobox, treeview and usercontrol) and it will stretch however way you like.
The Dock property is similar, but it also affects location and kinda "glues" the control to its place even in the form designer.

Categories