Appropriate anchor settings for TableLayoutPanel to achieve desired behaviour - c#

I am designing a form with WinForms, a partial screenshot of which is shown below:
The two buttons on the bottom are in a tableLayoutPanel, each one in its own cell. The "Add new baseline" button is anchored to the bottom and left, the "Delete Selected Baseline" button is anchored to the bottom and right. This partially does what I need it to do. That is, when the form is compressed horizontally, the buttons are also compressed, so that one doesn't overlap the other, for example.
They also need to stay in their exact positions as shown in the screenshot, when the form is resized vertically. At the moment, they are moving below and beyond the bottom edge of the form, or upwards and over the other button and the listView above. By the way, the listView is anchored to all sides.
I have tried several combinations of anchors for the tableLayoutPanel, and could not achieve the desired behaviour.

Related

C# - Responsive Winforms application positioning of pictureboxes

I'm currently trying to create a responsive winforms application.
What I try to archive:
I want to create a winforms layout which will have a responsive UI.
What is my problem:
I've added three pictureboxes(Close button / minimize application button / maximize application button) to the first row of the TableLayoutPanel.
Those three pictureboxes are positioned in the top right corner of the form. But the location of those pictureboxes won't change once I click the maximize button. Theyre staying at the exact position which makes them literally centered on the maximized screen.
Screenshot showing it:
What could I do to fix this issue? I appreciate any kind of suggestions and help.
What I have done so far:
Added a TableLayoutPanel which contains 2 Rows.
Added a Panel to the first row containing a pictureBox.
Added 3 more pictureBoxes to the pictureBox which are the buttons shown in the screenshot to close / minimize / maximize the application.
First, a TableLayoutPanel is quite a terrible control. It's hard to work with an has a noticeable performance issue once you get too many columns or rows. I suggest using two regular panels, one with Dock = Top and the other with Dock = Fill instead.
As for your buttons, I would position them inside the top panel, and set their anchor properties to Top and Right.
Further reading:
Control.Dock property.
Control.Anchor property.
You should anchor them to the right of their container. You should probably have a look at this:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor(v=vs.110).aspx

Hiding a panel should force controls below to move up and resize the form

OK, this is driving me a bit nuts at this point. Time to ask the crowd:
I have a form that consists of: two vertical "halves" created by a SplitContainer. Inside the bottom "half" / SplitContainer panel... I have:
A set of fields/controls for the user to fill out, contained within a panel.
Below that, a panel containing buttons for "submit", "cancel"...and one that's "show/hide". This "show/hide" is intended to show/hide the panel I just described in point 1 above.
What I want to happen is: when the user clicks to "hide" the panel of controls, not only do those controls vanish, but also:
The panel containing the submit, cancel and show/hide buttons moves up (so that we don't have this big blank space where the now-hidden panel once was).
The form resizes itself vertically so as to make up for the now-hidden panel and the fact that we've moved the bottom controls upwards.
I have no problem getting the panel of controls/fields to show/hide. But I can't seem to figure out how to accomplish the other two tasks. I've tried various combinations of AutoSize, AutoSizeMode, and Dock options.
Any suggestions?
If you put all your controls into a FlowLayoutPanel where the children are arranged vertically, then hiding some controls should cause the "lower" controls to move up the page.
You might still need to write some code to resize the form itself once the optional content has been hidden or before it's shown.

Autosizing pictures with Windows Forms

I need to place 3 picture boxes, which are all in a own panel, side by side.
Conditions:
all pictures should stay side by side in same distance to each other
the pictures should grow and shrink during resizing the Form
the Panels under the pB's should always act like a border to the pictures
it should be used as much as possible space
How could I do this in Visual Studio 2010 C#, Windows Forms?
I would suggest that you use a TableLayoutPanel with 3 columns, and place the pictureboxes within the given cells.
Anchor this panel to the parent form, so that when you resize the form, the panel will follow. Since you have panels underneath (as per picture sample) you could anchor to Left, Right and Top. This will anchor the panel to top, left, and will resize all the way to the right for as long as the form goes. Add Bottom if you need to.
The pictureboxes would have the Dock set to DockStyle.Fill.
You could nest more panels within panels, but do it in a sane way :-)
I think ,following these instructions will fulfill your requirements
1)right click on other panels and select bring to front
2)anchor the other panels to bottom
3)anchor all other panels panels and picture boxes to top,bottom ,left,right using properties
You can manage the interfaces selection ,un-selecting anchors

how to keep objects in place when window is resized in C#

How can I keep the objects of my window (buttons, labels, etc) in center when the window is resized?
Currently, I have 3 buttons in a Windows Form. When I maximize the window, the buttons stay at the top left section of the window. I want them to be in the center as they were when the window was not maximized.
Any help?
You should set the Anchor properties of the object to none,
This will keep it in the middle.
Set the Anchor property of your controls correctly. By default your control is anchored to Top,Left. If you clear this property (anchor to nothing, essentially), your button will remain centered.
(It may seem like you want to anchor to all four sides, but in reality what this will do is resize your button to fill the form!)
To keep your layout fixed and in the middle do this:
On your Form add TableLayoutPanel.
Set it's Dock property to Fill.
Create 3 rows and 3 columns.
Edit rows and columns - set 50% for first and last column and row.
Set fixed size for middle row and column.
Place Panel or anything else you like in 2nd row and 2nd column. It will always be in the middle.
If you are using the visual designer of Visual Studio (And you have no reason not to), the property of your control you seek to manage how they are placed inside a form is "Anchor".
By default, when you create a new control, it is set to "Top-Left", which mean they would stay in a fixed position to the top left of your form. You can change that to anchor them to anything.
You can also disable the anchors and control their position by overriding the Resize method of the form.

Center buttons in a container

How does one specify that a button centers itself in a container without having to specify a Location? Is it even possible?
The goal is to be able to center multiple buttons in a panel without having to perform calculations on their placement.
I know it is possible to center some controls on a form, not sure about a panel though. Anyway:
Disable the Left and Right anchors of your control if you want your controls to stay centered horizontally, and the Top and Bottom anchors if you want your controls to stay centered vertically,
In the designer window, select your control,
In the VS 'Format' menu, hit 'Center in form', then 'Horizontally' and/or 'Vertically'.
If you want to center several controls side to side, select them all and execute the above steps.
Controls will then stay centered in the form when the user resizes the window.
I'm not 100% sure of what you are asking, but try using a TableLayoutPanel, and drop one button in each cell of the table. If you anchor the TableLayoutPanel to the Top, Left, Bottom& Right, the Table will grow and shrink with the form, but each button will "float" relative to the top-left corner of it's containing cell.
Disabling all anchoring will keep the TableLayoutPanel at it's relative location within your form, but your buttons will remain spaced out evenly amongst one another.
Between standard control anchoring and/or the the TableLayoutPanel you should be able to find the correct type of anchoring that you desire.

Categories

Resources