We are not supposed to modify the contents of InitializeComponent(). Yet, the order that the designer adds our controls determines the stack order of Docking. For example, the designer might generate:
private void InitializeComponent()
{
//...
this.Controls.Add(this.dockTop);
this.Controls.Add(this.dockTop2);
Where dockTop and dockTop2 are of type Panel with Dock = DockStyle.Top. This results in dockTop2 at the top of the Form. If I want dockTop2 at the top of the form, then I have to modify the designer file (which we are not supposed to do as the changes can be over-written).
So, how can I set the order of my docking?
The order isn't set by the designer, it is set by you. Initially by the order in which you add controls. You can alter the order by right-clicking a control and choosing Bring to Front or Send to Back. Get fine-grained control over the order with View + Other Windows + Document Outline. You can drag+drop a control in the list to move it.
The standard way to manipulate a form containing several docked controls, as I understand it, is to Cut the panels, groupboxes, whatever and Paste them back in in order of precedence.
Related
i have a form with a few controls on it, i have a panel with different controls on, That panel is above the form controls.
i have added new controls to the form and when i place the panel back over the form, the new controls are showing through the panel itself, but only the new one controls and not the "old" ones, if i copy and paste a control or add a new one it has the same effect.
i have looked in the designer.cs and the new controls are being added to the form and NOT to the panel itself.
this is weird and iv checked various properties but cannot immediately see the reason for this.
i have made MANY forms before and this is the 1st time this is happening.
one the note of controls, is there a way to change the default value of the labels "AutoSize" property from TRUE to FALSE; i'm using visual studio CE2015
any ideas on what to check? im really stumped by this one.
As mentioned in the comments, you need to check the z-order of your controls.
In the picture below you can see a form I created with two buttons and a panel as you were describing. Neither button is one the panel, however button 3 has a z-order that puts it on top, just as the panel is on top of button 2
If you right click on the controls you want to change the z-order of you see Bring to Front and Send to Back. Choose the appropriate option.
I have a "cross section" of variables that I need to use to generate a set of user controls dynamically. In the center of the page I have a Telerik multitab/page. I have a custom tree menu and a custom menubar, based on the combination of menu input each of the tabs should load a user control relevant to that cross section of data.
For clarity, almost each tab, treeview, menubar combination needs a unique control.
My problem is that all the postback/loading happens well before the "OnMenuChanged" event triggers, so I'm one "set" of user controls behind. Even if I were to use session/viewstate they wouldn't get assigned until after I needed the value stored in them.
Currently what is happening is the default user controls are loaded in the "pageviewcreated" event, then in the onMenuItemChanged I go back and reload the user controls. It seems very inefficient and is complicating up the approach for selecting the right .ascx.
How do I manage this?
If I understand what you're trying to do could you not use a placeholder control and inject your needed usercontrol into that inside of the events you're managing? Try doing something like this inside of the "OnMenuSelected" event.
WebUserControl1 uc = (WebUserControl1) Page.LoadControl("WebUserControl1.ascx");
PlaceHolder1.Controls.Add(uc);
I'm using different sets of controls on the same location on a form. By default all are visible=false and then certain subsets of the controls are set to visible as the user selects specific values in a combobox dropdown control.
From the user's perspective this works well since they only see the controls that are needed.
However, since the controls occupy the same location on the form it is difficult to manage these in Visual Studio design view.
Is there a way to group sets of these overlapping controls in Visual Studio so that I can select the entire subset of controls quickly and easily? Is there a way to hide certain controls in design view? Right now everything is stacked on top of each other when developing so it makes managing these controls difficult.
To get such a beast to work i would put every group into it's own UserControl. On your MainForm you stack all these UserControls above each other.
So at the MainForm you can't really get a good overview, but now you got for every group your individual designer view and in your main form you can hide the complete group by a single line of code userControl.Visible = false.
A TabControl can do this, works well in design mode. You just need to hide the tabs at runtime. Check my code in this thread.
You can not hide them.
However you can group them in group box
and using "Bring to front" and "Send to back" property deal with them.
First of all,
If you work with multiple components in same location, you can use groupboxes in your form. Then, to superimpose these groupboxes, you should edit each of your groupboxes on different place in your form screen. After the edit, you should input size and location data manually in your groupbox properties menu.
If you want to edit one of your groupbox after the set location, you can easily right click any of your groupboxes then click "send to back" and "bring in front" commands. I hope it helps.
I want to create my own custom control that is basically a TableLayoutPanel with 3 rows and 1 column. The top and bottom rows will contain labels (banners) and the middle row is where I will add other controls. The problem is that when I try to build other forms/controls from this control, the designer doesn't recognize the middle panel. How do I get it to? If I drag a textbox to the middle and set Dock=Fill, it will cover the entrie form/control. Also, is there any way to get the designer to reject dragging of controls to the top and bottom (banner) rows? I've tried the steps in the following link but haven't had any luck (http://support.microsoft.com/?scid=kb%3Ben-us%3B813450&x=21&y=15).
I figured it out. The trick was to create my own designer that inherits from ParentControlDesigner and overrides the Initialize method and calls EnableDesignMode for the inner content panel. On top of this, I needed to set the Designer attribute of my user control to this new designer. The details are shown here.
One problem, though. I can drag controls to the content panel I created and everything looks fine. But, once I recompile, the controls disappear. They are still there, I just think they're getting drawn before the banner panel. I will create a separate thread for this problem.
I have been able to create a custom C# winforms control that is basically a panel with a fixed banner (header/footer). I want to base other user controls on this "banner panel". I've gotten past the problem with the designer here. I can successfully add controls to the inner content panel. Everything looks fine while designing. However, when I recompile, the controls I added to the content panel disappear. They are still there (in code) but aren't displayed in the designer. Is there any thing that I need to do to set the drawing order of the controls?
Your controls are still nested correctly within the panel control, they have just lost their z-order. If you choose the controls from the property panel and right click on the control border that appears within the parent panel and select "Bring To Front" from the layout toolbar, your nested controls will re-appear. I don't know why it does this, but a workaround is to bring all child controls to the front during control initialization in the code.
There is really nothing to go on here without src. What I would do is to comment everything out including in the InitializeComponent function but a widget in the middle panel and run. Do whatever it takes to get that one widget to show. Inherit from UserControl instead of the banner panel.
Then comment in each piece until the widget no longer comes up. That is what is causing your problems. Once it all comes up properly, then you make sure the designer portion of the src works. It is going to potentially be a long process.