How to drag, drop & swap pictureboxes in tablelayoutpanel - c#

How to give TableLayoutPanel functionality to drag drop controls between cells and swap those controls?

It would be feasible if the TLP is fixed size in rows and columns and not autosizing (because an empty row or column may disappear). And it may help to fill each cell with a Panel as parent of your controls, so you only have to swap the content of panels. Managing controls in the TLP cells themselves is a bit more complex. Come to think of it, when using a TLP in such a restricted way you might as well draw a grid of Panel controls yourself.

Related

Can't get anchor to dynamically resize control

I have two controls in a groupbox ("Waveforms"). I would like them to dynamically resize also by height but can't get it to work. I've used left|top|right anchor for 1st control ("Left channel") and left|bottom|right anchor for 2nd ("Right channel").
Here is a short video of problem.
How can I acomplish this?
If you want your controls to share vertical space of the GroupBox, you can use a TableLayoutPanel or a SplitContainer.
By using a TableLayoutPanel you can easily specify how the vertical space should be shared by controls. For example you can add two rows to the TableLayoutPanel and give them each 50% of the whole height.
By using a SplitContainer, the user can change the occupied heights of the controls at runtime.

Customizable table/label to make a matrix

I am trying to use Visual C# to make an editable row/column matrix. Essentially what I want to do is this:
The Row and Col values will be editable and i would like for the amount of cells to resize inside its bounds. That is, if i change the rows to this:
The bounds should stay the same.
What sort of Container should I begin using? I have tried a panel control with coloured labels but I can't think of how to resize them?
Just drag the DataGridView control from your toolbox onto your form:
I've used the following code before to distribute the column widths evenly:
base.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
An AutoSizeRowsMode property also exists.

winforms adjust controls to push up vertically when others are invisible

I've create a c# winforms form,
It has a bunch of labels positioned and a flowlayoutpanel.
on certain occasions i set one of the labels and the flowlayoutpanel to visible =false.
As a result i want all labels beneath them to be pushed up - at the moment there is a gap where they were.
Also, I'd like the flowlayoutpanel to grow and shrink depending on the number of items it has.
at the moment it is just the size i set it to be in the designer.
please can you help with these 2 issues.
Thanks
If I got you correctly, I would suggest using a TableLayoutPane with two rows. The top row will contain a docked panel with all the controls that may be hidden. The bottom row will contain a docked panel with all the rest.
Set the top row's SizeType to AutoSize and the bottom row's to 100%.
When you want to hide the controls, set the top panel's Visible property to false. Now, because the top row is AutoSized it will shrink to nothing, causing the bottom row to "jump" up.
The TableLayoutPanel does the pushing. Maybe you can use that if there is no better answer in next time.
First problem:
You may use some simple panels to divide your form, give them the dock.fill property. when you'll hide a panel programmatically, the other panels will fill the empty space left.
Second problem:
You have to set the Autosize property to true.

How can I add a bunch of labels to a C# form and then scroll the form vertically?

I have a form in C# (WinForm). It looks like this:
(LOGO)
blank space for labels that I add
through code (I can fit 10 labels in
this space)
(close button)
The blank space can hold about 10 labels.
I am stumped on how I would make this form scrollable if I want to add 20 labels? If I add 20 labels via code, then the 11th label will overlap with my close button and the 12th+ label(s) will run off the end of the form.
How do I make just the blank space portion of my form scrollable where I am creating the labels? I don't want to use a listbox.
Thanks.
You should try using either a TableLayoutPanel or a FlowLayoutPanel as a container for your Label controls.
A TableLayoutPanel will allow you a finer level of control over where your labels are positioned. Like an HTML table, you specify the exact cell position (using row and column coordinates) of each control.
By contrast, a FlowLayoutPanel will handle the positioning of its contents automatically, either in a vertical or horizontal layout configuration. The positioning is determined by the order in which you add the controls, allowing you to achieve a dynamic layout with a minimal amount of fuss.
Either will allow you to add your label controls to it at run-time and size itself appropriately. In order for layout panel to be scrollable, make sure that you set its AutoScroll property to "True".
Maybe a FlowLayoutPanel with AutoScroll set to true and FlowDirection set to TopDown.
Place all controls inside a panel and use scrollbar control.
Understand .NET Scrollbars
You could use a FlowLayoutPanel.
Add as many labels you need and enable AutoScroll on the FlowLayoutPanel.

c# winforms evenly distribute 3 controls

i have 3 custom controls, that i want to place in a resizable window next to each other. when the window is being resized, these controls should also resize, each taking 33% of the available width.
i tried to use a table layout, but it seems the table only grows, but never shrinks.
thanks for any help on this!
You can use a TableLayoutPanel, with 3 columns each of size "33% percent". Then you put each of your control in the panel, and set the anchor property as you wish (for example right-left if your control should resize themselves only on the horizontal plane).
Your TableLayoutPanel should also have its property Dock set to True so that he can occupy all your window and resize accordingly.

Categories

Resources