How do I create a banner panel in C#? - c#

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.

Related

why are new controls showing up in my form AND panel

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.

Control Dock.Top order without InitializeComponent()

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.

adding controls to tableLayoutPanel

I was wondering if it was possible to add more than one item into single tableLayoutPanel?
Currently, I can only insert ONE item, it won't accept anything else. I would like to have for example a richtextBox with label and button inside it. Is is possible? Thanks! I'm not asking for code, I just need to know if it's possible to manually drag and drop these items into single cell in tableLayoutPanel.
It appears you are only allowed one control per cell, if that is what you mean. You can always add a container control such as a panel with it's Dock property set to Fill you can then add your additional controls to it. Or add another tablePanelLayout Control to the Cell and set the row / columns how you need and then add your controls to that. Or as LarTech mentioned in the comments a UserControl would work also.
You Can also add a Panel Control and then add all other stuff to the Panal
Add a container such as a GroupBox or Panel, and set it to fill all available space in the table cell, and that could override the TableLayoutPanel's "one per box" rule so you should be able to add as many controls as you wish

Adding the same Panel to multiple TabPages

In my previous question I could add a design time panel to a tab page at run time and my code looks like this and it works Ok.
tabControl1.SuspendLayout();
tabControl1.TabPages[0].Controls.Add(panel1);
tabControl1.ResumeLayout();
but now I need to do something like this:
tabControl1.SuspendLayout();
tabControl1.TabPages[0].Controls.Add(panel1);
tabControl1.TabPages[1].Controls.Add(panel1);
tabControl1.TabPages[2].Controls.Add(panel1);
tabControl1.ResumeLayout();
which just at run-time I can know how many of these Tabpages I will need. but now for testing I am assuming I will have three tabPages
the Problem is that the panel only gets added to the Last tabPage,
How can I fix this? I want it get added to all of the tab pages
Thanks.
You can't. A control can have only one parent at a time. Luckily, only one tab page is visible at a time, so I guess you could move the panel between the pages as they are displayed? On the other hand, if the panel is to be located in the same place for all pages, perhaps it should not be placed inside the tab control, but rather on top of it?

Why are controls within custom panel (C# winforms) disappearing in designer?

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.

Categories