Menu Strip and Status Strip conceals the form elements - c#

I have a menu strip and status strip whose Dock property is set to Top and Bottom respectively. I need to display a table (i.e. TableLayoutPanel object) programmatically which covers the full form so I have set its Dock property to Fill. The problem is that the status strip and the menu strip covers the top and bottom parts of the TableLayoutPanel object, concealing it. How can I avoid that?

You could add a Panel to your form via the designer. Stretch it out so it covers the area where you want your TableLayoutPanel object, then set the Anchor property of your new Panel to Top, Bottom, Left, Right.
Then just do panel1.Controls.Add(tableLayoutPanel1);

For this problem there is a table layout panel (which you were already using, so you were almost there).
Instead of docking your controls to top or bottom you make a row for the control in the table layout panel and just fully dock it.
Example of table layout panel with 3 rows and controls docked:
As you can see they don't overlap and the tablelayout panel takes care of sizing (you can set % per row, or fixed px etc.)
So what you essentially need is a table layout panel to hold your table layout panel

Related

How do I make the widths and lengths of an object automatically resize?

How do I make the widths and lengths of an object automatically resize?
What I mean by this is that I'm trying to make my design responsive. The problem is that when a user resizes my app, the objects don't fill the empty spaces that are created (E.g, a box has the same problem).. I'm using Visual Studio and I'm not sure if this is a property or a programming issue..
In winforms, controls have a property Dock. You can set it to Left, Right, Top, Bottom or Fill. If you set the Dock property for the various controls in your form, they will fill the available space whenever your form is resized.
Usually, the "main" control on your form will have a docking style of Fill, while the main menu toolbar will have Top, the status bar will have Bottom and so on. Play around with the Dock property until you get your form organized right.
You may also have controls that must keep a fixed size when their parent form is resized, but must align to one of the edges of the form. For this purpose, controls also have an Anchor property. Set it to Left, Right, Top or Bottom.

WinForms: How do I keep a panel from scrolling with the window content?

I have a navigation panel on the left hand side of my program and I'd like it to always stay where it is when scrolling the window content. Is there a way to do that?
I've thought about trying to do a get/set for its position but there's only a size property.
In the example above, the information in the top left is in a panel. Is there a way to keep it anchored there as the user scrolls down?
You currently appear to have the Autoscroll option enabled on the Form. Set that to false, then set up two panels, one for the toolbar/navigation and the other for the scrollable content.
Set the toolbar panel to be anchored to Top, Bottom, Left. Set the content panel to be anchored to all four sides. Set both panels to Autoscroll=True, then put the content in each panel. When each panel gets too small to contain their contents they will scroll - independently - which will in most cases mean that the toolbar/navigation will stay put while the content will be scrollable. If the toolbar panel also gets too small then it will be scrollable too:

How do I set dock property of a datagridview properly?

In a datagridview when I set:
Anchor: Top,Left
AutoSizeColumn: Fill
Dock: Fill
Which will expand or shrink the datagridview based on size of the form, and covers the whole form. But what of I have controls on the right side on the form? I don't want to overlap my linkbuttons with my gridview. I know there's a "Margin" and "Default Cell Style" property with padding values (specifically using "right padding" to try and reduce width from the right of the right edge of the form). So I tried messing with that, didn't do anything I want. Or was I working with the right properties, just not setting them right?
Put those controls you want on the right in a Panel.
Set the DockStyle of that panel as DockStyle.Right.
If you can't see the right edge of the Datagrid means, you have to bring the Datagrid to front by selecting it, right click and choose bringToFront.
Or Send the Panel to back.
1.Use a panel to split the form into two sections.
The right section is placed with DataGridView, and the left section is placed with a panel which is used to contain your other controls, like linkbuttons.
2.Set the Dock property of this panel to Right.
3.Set the Dock property of this DataGridView to Fill.

Resize components inside user control while maximiziing

I am using c# and i am creating a simple design where i have a user control and some components inside it like treeviews and buttons. I am trying to fill a treeview with some nodes and drag-drop these nodes to other treeview and use the buttons to also copy nodes from side to another.
The problem i am having is that when i maximize the window containing this user control there is no effect on the inside components.
I have set the Dock property of the user control to Fill.
I have changed the anchor properties of the buttons and treeview inside the user control but the behavior wasn't as expected. For example i have tried to set the anchor property for the right treeview to be Top,Bottom,Left => and the result was a disaster
I have also done a lot of combinations for the anchor property of all the buttons but nothing gave me the right behavior. I just only need to maximize the window form and the controls will be maximized with the same proportion.
It sounds like you want a "3 column" interface where you have a TreeView on either side and Buttons in the middle to allow movement between the two. Assuming this is correct, you can accomplish your automatic resizing by using a TableLayout.
Essentially, it would be like this:
Add a TableLayout and edit the rows/columns such that there is a single row with 3 columns:
The first and last column would be sized at 50% (and would hold your TreeViews).
The middle would be an absolute size of (for example) 120. This would hold your Buttons.
Set the properties of this new TableLayout to Dock -> Fill the form. This will size the entire table to grow with your form.
Add your TreeView controls to the left/right columns and set them to Dock -> Fill the respective columns. Since these columns are dynamically sized, they will grow with the form.
In your middle column, add a Panel and set it to Dock -> Fill. We add a Panel here to hold the multiple Buttons you use for movement. This Panel will not grow in size because the middle column is sized absolutely.
Add your Buttons to the middle Panel.
Without a screenshot, I'm not completely sure what you are trying to achieve but I believe this is along the lines of it. The nice thing about this setup is there is zero code involved.

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.

Categories