Windows Forms project, working only in designer (i.e. with mouse, before the compilation). I have a Form and 2 Panels in it. panel1 is docked (option - fill) in form1. panel2 is docked (fill) in form1, too. Also, panel2 is in front of panel1 (the latter is hidden behind the former). My problem is - when I undock panel2 and dock it again - it docks in panel1 (panel1 becomes it's parent) and not in form1. How can I change the parent of the panel2?
The only solution I figured out so far is cutting (ctrl+x) panel2, selecting form1 and then pasting (ctrl+v) panel2, but this, for some reason, removes all connections between panel2 controls and the code (for example clicking the button on panel2 doesn't work anymore although the function handling the event is still there).
Any better ideas?
Cutting controls to the clipboard will sever the event handlers, so best to stay away from cut and paste in the designer.
Since you are using the designer, open the Document Outline panel from the View - Other Windows menu in Visual Studio. Use the Arrow buttons to properly set the parent or the docking order of the controls.
The Document Outline window looks something like this:
Seems people liked my commented answer so I am putting it here as an answer
You can undock panel1, then move panel two out of panel1 onto the Form1 background. I have struggled with this as well. that was always my work around, I too found that cutting and pasting it cause a lot of haedaches. It can also be fixed in code, using the designer file
The panel can't change Parent when you change is dock !!!
Or I not really anderstand your problem.
But... if you want change the parent. Just remove the panel of the list of Control of the Panel and add it on the list of Control of the form.
yourPanel.Controls.Remove(yourOtherPanel);
yourForm.Controls.Add(yourOtherPanel);
yourOtherPanel.Dock = .....;
Related
What do I have to do to see the panel with the things inside which is under the second panel in Visual Studio?
I want to change something in panel1 but i cant see any labels and buttons because panel2 cover it. I dont want to change position of panel2 so what i should do?
that border is button1 border. How to see that button which is covered by panel2?
Changing panel2 Visibile doesnt work.
Panel1 is good option to make pages? Maybe groupbox?
I know from the TabControl to see it's content that you have to click on the tab header in the designer, like you would do on the running program.
Maybe that helps.
So I have three panels all stacked on top of each other in the same location in a windows form application.
Each time I add another panel on top it becomes a child of the previous panel. This means each panel cannot be shown independently, ie, to show panel 2 I must first show panel1 (the parent). I'm fairly sure this is what is happening. However I need to be able to call panel2.show(), whilst panel 1 is hidden.
Is there a way to work around this?
This is a WinForms designer issue. You can either try moving the panels around and set the position in the properties or enter code behind and set the parent-child relationships manually.
basically don't just drag and drop panels on top of each other. Try to programmatically code their locations. Look for this kind of code in your Form.Designer.cs this.panel2.Controls.Add(this.panel3); and delete them.
Add all your panels in the form part which is supposed to be at the bottom.
this.Controls.Add(this.panel1);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel3);
This should be able to put all panels as form children.
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.
A Windows Form application displays a main form. This main form contains few different Panel controls. Depending on some condition in that form one of these Panel controls is to be made active while the others are made invisible.
First panel contains a DataGridview, Second panel contains controls to display the details of the DataGridView. On Add button click (or) On selecting a record in DataGridView the second panel should be visible. I am using Visible property to show and hide panel, but the gap is showing there as shown in screenshot.
Please suggest best way to handle this.
You just need the panels to share the same location. You probably don't want to do that at design-time, as it makes future maintenance of the form difficult.
In the Form.Load event, set the location of the bottom panel to match the location of the top panel.
PanelDetails.Location = PanelDataGrid.Location;
Now when you hide one and show the other, they'll appear in the same place.
The smartest way is to keep the panels separate at the designer. This way any editings made on them can be done more easily, and all actual objects can be seen immediately.
In the designer, set the other panels' Visible properties to False, excep the first one on the top.
Form.Load:
Set all the other panels' locations to match the location of the first panel (on the top)
Set the form's height to match a desired height, which fits to your heightest panel
Use the buttons to toggle panels visibility (and possibly the form height too)
I've tried looking many places for an answer to an issue I'm having and so far I've found nothing.
What I currently have is a c# windows form with user controls inside it. Some user controls have other controls inside them. What happens when I change the text in a textbox, is its parent windows will no longer resize like they should when changing the window size. i.e. A horizontal scrollbar will appear even though horizontal scrollbars are disabled in that specific window. Its almost as if changing the text changes the parent window's styling.
In case this is too vague, I have a textbox inside a panel with a docking property set to fill. The panel has a padding of 10 in order to allow the textbox to have some white space for aesthetic purposes. This control resides within a parent control (we'll call it parent 1), which in turn resides within another control as well (we'll call it parent 2). So when I change the textbox's text (at all, even adding a space), will then make parent 2 have a horizontal scrollbar flicker and sometimes even remain when resizing the form window manually.
You should make sure that not only the TextBox in the UserControl is docked to fill but also that the user control itself and its parent (and its parent) are Docked correctly or have anchor set so that they resize with the Form.
Do you execute any special code when the user enters a character? (KeyPressed event etc.). If yes you should try disabling the events temporarily to see if they cause the problem.
If you post a sample of your code it would be easier to help. Without this we can only guess, like I tried...
I found out my issue! When using autoScrollBars and double buffering, it caused the horizontal scrollbar to show when it shouldn't have (at least in my case) when resizing the window. The answer was simple, forget the autoScrollBars, and implement my own vertical scroll bar!
I was actually getting some code to post up on here for you guys to look at, but when looking at it, I decided to forget the autoscroll, and lo and behold it worked!
I'm actually curious as to why that is though. My friend heard that .net has some issues with autoScroll but I didn't think it would be to this degree.