C# tablelayoutpanel panel control - c#

I have a tablelayoutpanel divided in 4 columns and 4 rows. by using Panel box = new Panel(); I filled in all 4x4 tablelayout panel with panels. now I have to delete in example a Panel which is in 2 collumn and 3 row. how do I do that?

There are a few ways to do it, but try this one;
tableLayoutPanel.Controls.Remove(tableLayoutPanel1.GetControlFromPosition(col, row));
This is assuming you're just trying to remove the panels (As they would be child controls to the tableLayoutPanel).
Otherwise you could remove directly by passing the actual panel you want to remove through the method;
tableLayoutPanel.Controls.Remove(panelYouWantToRemove);

Related

Set static control at the top of TableLayoutPanel

I have a TableLayoutPanel and inside it, I want to add FlowLayoutPanel
So I added it and it works, but now I want to know how can I make that FlowLayoutPanel static at the top of TableLayoutPanel because when I scroll TableLayoutPanel the FlowLayoutPanel just disappear because is at the top of the list. Is it possible to set static control inside a TableLayoutPanel?
I don't know if there is a way adding frozen row to TableLayoutPanel. But you can make this:
Don't add FlowLayoutPanel on that TableLayoutPanel. Instead, use another TableLayoutPanel with 2 rows and 1 column. Add FlowLayoutPanel to the top of the new TableLayoutPanel and add your actual TableLayoutPanel to 2nd row with autoscroll enabled. At the image: the blue one is outer TableLayoutPanel, the black one is FlowLayoutPanel and the gray one is inner TableLayoutPanel. I set Margins as 5 to show all objects, you can set Margins as 0.

TableLayout filling the whole space when one of the two is invisible

In Winforms, I have 2 tableLayout A and B sharing the same space. I would like to switch between them (e.g. via a button), only one visible at a time so that they fill the same space.
What I have tried, following some post : put them both into another TableLayout X as container, with 2 rows, the first row Autosize and the second put as Fill.
I managed to achieve the following : when A is invisible, row 1 Autosize reduce the size to 0 and bring B up, filling all space. But when B is invisible, A does not take all the space.
How can I make A to take all the space ?
Thank you.
Here is what happens when A alone is visible
Here is what happens when B alone is visible
I tried the following in my application. I have to show forms one by one in table lay out. For that, I removed the control(form1),from first row and added another control(form2) to the same row.So,you should also try like this with tablelayout control.
var control = tableLayoutPanel23.GetControlFromPosition(0, 1);
tableLayoutPanel23.Controls.Remove(control);//removed form1
tableLayoutPanel23.Controls.Add(frm2, 0, 1);//added form2
frm1.Dispose();
frm2.Show();
There should be 1 tableLayoutPanel which should have 2 rows and 2 group box in each rows. You can make both the groupbox dock property as fill. Inside You can pro-grammatically change the height of the row by using:
tableLayoutPanel3.RowStyles[0].Height = 0;
Thus when A is invisible B will take the full size of the tableLayoutPanel and vice versa. In case both groupbox visible then the group box will take the size of each row of the tableLayoutPanel:

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 to drag, drop & swap pictureboxes in tablelayoutpanel

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.

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.

Categories

Resources