Forms designer : How to make a control ignore a flowlayoutpanel? - c#

When using the forms designer I ran into a small problem (I could solve this with code but I wondered if there's an easy way.)
I have a flowlayoutpanel and when I drag a new control on it (for example a label) it will give it a position in the flowlayoutpanel and I am unable to move it other then changing the order with other controls.
The question : Is there a way to add a control on top of a flowlayoutpanel ?(So ignoring the auto arrangement.)
Extra info : The reason I want to know this is because I am using the height of the flowlayoutpanel for the creating other forms and I rather keep that code as is.

One way is use arrow keys. Place your control out side flowlayoutpanel then use these keys to move it to top of flowlayoutpanel.
You can combine it with Ctrl key, which some times turn out very helpful because it will move you control to the places which one of your control borders is on samle line with one of other controls.
One other way, you can set Location for control directly, if you know the exactly where the control should being add.

Related

Copy-pasting Docked Control in C# Designer

I am designing the UI of my program with a TableLayoutPanel, with each control docked in its cell with Dock = Fill. Since a lot of the controls are similar, I want to use copy-paste to populate the layout. However, the newly pasted control is put in the bottom-left cell by default. Furthermore, since it is docked, I cannot move it in the designer, so the only way I could put it in the correct cell is by setting Dock = None, drag it, then setting Dock = Fill again. This is very annoying, and to some extent defeats the purpose to use copy-paste in the first place (to avoid forgetting to set Dock). Are there any better ways I can create such a layout?
I just found out that, when put into a TableLayoutPanel, the control has a Cell property. Modifying it allows me to move the control within the TableLayoutPanel without first undocking it.
Of course, Hans Passant's suggestion of first moving the controls, then mass-set the Dock property also works.

Why do some objects appear on top of others, and not always like that?

I created 2 empty labels, using winforms, to cover some groupboxes
They were created exactly the same way, but they dont behave the same way
The first one:
The second one:
The first covers everything, the second one only covers one groupbox, and displays the other two.
I tried the right click+ send to back /send to front, but I believe this doesn't mean anything in the code, it only purpose is to allow you to visualize better what you are placing in your form, I guess.
Can someone shed some light?
Groubox, Panel, TabPage etc are containers in which we keep controls. Form itself is also a container..
When you drag a label or any other control to place in a form, and if you want to hide the other controls, you should place the label in the form itself and the label should not become child of any of the groupBoxes.
For that the left top corner of the label you drag should not go inside any of the groupBoxes. This is only when you drag. If you want to position at a point inside groupBox, then Drag the control outside the groupBox and then use keyboard arrows to position, this will not let the control to become child of the groupBox. You can also set position on property window.

Delete a SplitContainer without deleting other controls

I can't believe I couldn't find the answer to this....
I no longer need to use a SplitContainer in my WinForms UI. But whenever I delete the SplitContainer, I lose all of my other controls too -- buttons, labels, textboxes, and charts. Anything that was in the SplitContainer is deleted as well. Very annoying.
What is the best way to remove a SplitContainer control but leave everything else in place?
Trivial Example:
Make room on your form and drag those controls into the empty space.
Alternatively, go to View - Other Windows - Document Outline and move the child controls out of the SplitContainer's hierarchy.
Do not cut and paste since that will sever your event handlers.

Ungroup panels?

So I am working on a program that has several screens which causes it to have overlapping controls (Buttons and lists).
I put the controls in panels which works great and then do show/hide for the panels.
This also works well.
I am having a problem now that I am up to several panels where when I move one panel up it gets absorbed by another and I need them to stay separate.
Example: When I move panel2 into place over panel1, panel2 becomes part of panel1. Then when I do panel1.Hide() and panel2.Show(), panel2 is still hidden because it is part of panel1. is there a way for me to ungroup these or move panel2 into place without it automatically becoming part of panel1? (I know I can show hide the controls inside of the panels, but this will add a lot of complexity because I have a ton of controls)
Perhaps there is a better solution than using panels?
You can use the View + Other Windows + Document Outline tool window to get these panels separated again. Drag the inner panel back to the parent. You'll then also have to edit the Location property to get it back in the right position.
This is annoying of course and good odds that you'll have to do this repeatedly. There's a better way to go about it, a TabControl has good design-time support and also has the same "overlapping panel" metaphor. You just need to hide the tabs at runtime. That's pretty easy to do, check the StackPanel control in this answer.

Prevent Child Components when Overlapping Panel

I have a WinForms application which has two panels which individually contain a usercontrol component (one in each panel). How ever, because both panels are the same size and in the same location, the top most panel becomes a child of the other panel. I want to be able to hide one panel and then show the other panel:
this.panel1.visibile = false;
this.panel2.visibile = true;
But when I hide panel1, the second panel is hidden as well.
How can I make panel2 a non-child of panel1?
I like to keep things simple because I'm new to C# Programming.
This is a common accident in the designer. Dropping the second panel on top of the first one will make it a child of the first panel. Two basic strategies to fix this:
View + Other Windows + Document Outline. Click the second panel in the list and drag it to the form. You'll need to fix up the Location property by hand by typing its value in the Property window.
Keep the upper left corner of the second panel just a bit to the left or top of the first panel. Put it in the right place in the form's constructor by assigning its Location property after the InitializeComponent() call.
Check this answer for a control that works well at design time and lets you easily flip panels at runtime.
The designer will do this automatically because it assumes that when you drag one control over another, you want to make it a child of that control.
What I usually do to get around this is to create the control in a different place on the form, and then use the properties to manually match the positions of sizes of the two controls.

Categories