I am beginner in c#. I have some problems with arranging the controls on a winforms. In my project, I took one tabControl and gave the property dock --> fill. After implementing all the designs, I remembered that my form need panelHeader as well as panelFooter. when I add them and given property dock -->top and dock --> bottom respectively, these panels are coming on top of the tabControl. I tried to solve this by removing dock --> fill to tabControl and setting it again. but no use. How to solve this problem? (i dont want to delete tabControl and redesign because it took me 4 hours for design).
If this is a waste question then please only comment so that i can delete this question later.
Please Help
Thanks in Advance.
EDIT:
Well i handled it by using cut and paste properties.. but what if there are more controls to take care of (if so then it will make the form messy).
Try right click on the control and click "Bring to Front". I remember trying this long before I am not sure that this answer is correct.
Temporarily set Dock = None for Tabcontrol......... add a TableLayoutPanel with 3 rows in your form.
1.In First row u can add "panelHeader" and set Dock for it
2.Select TabControl and move it to tablelayout second row set the Dock = Fill
3.In last row add your "panelFooter"
You have to write in your Designer.cs page this code
this.yuortabcontrol.Dock = System.Windows.Forms.DockStyle.Fill;
And instead .Fill you write as per blow image in tabcontrol
Related
I made a simple Form with a TableLayoutPanel and a button below it.
Is it possible to create another TableLayoutPanel below the one I already have on each button click?
And how can i fill it with data?
I searched for many hours but didn't find anything.
Here is a screenshot of my form, if it helps you:
I want the other tables to appear on the lower half of the split.
Thanks in advance, Jan
Of course you can. You may want to consider adding the TableLayoutPanels to a FlowLayoutPanel so that they will wrap and scroll automatically.
Just create the control, setup the columns and rows, then add it to some container:
TableLayoutPanel tlp = new TableLayoutPanel();
// setup "tlp" with your desired properties
tlp.XXX = YYY
// ...
flowLayoutPanel1.Controls.Add(tlp);
Context :
I created an User Control. For some reason, I want to use this control in different size. To keep the initial "Template" of my User Control when re-sizing, I use the property Anchor on my different element inside the control.
So when I create my control at design time, it is possible to me to hand re-size the control and keep the original "Template" of it.
When the control is created, it look like this :
And after re-size :
As you can see, the property Anchor work well.
The label and the picture stay in the middle.
The "?" stay to the left corner.
The problem :
The problem I have is, when the control is reloaded, created with a different size as the initial one, all the elements inside return to their initial position :
I don't know if this is the better way to do what I try to achieve. Keep in mind that I add and re-sizing the control's during the design time.
Thank you.
EDIT :
I think my problem is caused by the designer. Ex : I add my control in the designer, I re-size it, I run the solution. All is working good. But when I go to the code of the page, and then, return to the designer, the element inside the control returned to their initial position.
EDIT 2 :
Ok I have found a solution, I simply moved all the element of the User control inside a Panel. For some reason that I can't explain, it work perfectly. The control's stay at the same location.
The solution is ta add a Panel to the User Control and dock it to "Fill", then place the element inside of this panel. For some reason that I can't explain, the designer keep the location of the re-sized control's elements.
The anchoring, docking and auto-sizing of a UserControl seem to be terribly confusing. I found UserControl does not auto resize with the Form which suggests that you set the AutoSize property to False, which I did, and it still didn't correct my problem. But when I tried your solution, I also noticed there are two copies of the AutoSize property! I had set the AutoSize in the UserControl designer to False, but the Form designer where the UserControl instance was added also had an AutoSize on the instance, and that one had a different value (it was still True). When I set that to False also, then everything worked (with the panel in place). Then I removed the panel you suggested, and everything still worked. So I guess the trick is to make sure you check all the properties of the UserControl in the UserControl designer and in the form designer where the control is used. Then you shouldn't need a panel.
I've had similar problem in VS2015 project, and unfortunately - none of your answers helped. Clean and working solution was found here, in Jignesh Thakker answer.
For quicker navigation here it is how it was done in my project (c++/cli, not c#, but idea is the same):
System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
/* some code */
myUserControl = gcnew MyUserControl();
myUserControl->Dock = DockStyle::Fill;
tabPage1->Dock = DockStyle::Fill;
tabPage1->Controls->Add(myUserControl);
/* some code */
}
Set the Localizable property of the parent form at VS designer to false. This solves the problem at design time. (Save, close and reopen the form after switching the property)
If you need a localized application switch the Localizable property to true after finish up working at the layout and don't care about the wired representation in the VS designer. At run time it's shown correctly.
Tested in VS2013
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
so I have started from 0 and defining tabindex for the controls on my form but at run time it is all messed up. the form is a little complex tho. it has horizontal and vertical splitters and panels, group boxes and some older VB 6.0 activeX controls which is a Tree control inside them. even if i do it programmatically and read previewkeydown eventg and say if it is TAB then control2.Focus() it is still working wrong. so frustrating. any thoughts? ..there are also labels on the form which do not need tab so I have defined 0 for their index.
How are you setting it?
If you are in visual studio with the form in design view select view -> tab order and then click on each item in the order you want them.
Usually works for me.
The reason is that the controls are in different Containers. Suppose you've got panel1.TabIndex = 0 and panel2.TabIndex = 1, then in panel2, textBox1.TabIndex = 0, in panel1, textBox2.TabIndex = 1. At runtime, textBox1 comes before textBox2 because its panel comes first!
As kerry said, use view->tab order to see the complete hierarchy of tab orders.
I'm mentioning this because I haven't seen it in any of the winforms tab order threads that I have found on stackoverflow.
If you have multiple panels, you change your panel tab order by clicking on the Panel, going to properties, and then you change the TabIndex to whatever you want. This will allow you to navigate from panel to panel in the order that you want. Then within each panel, follow the recommended steps listed above using view > tab order and click on each cell in the order that you want to set.
Follow the steps below:
Set the TabIndex property to DIRECT CHILD containers and controls in your form or container, either using the View > TabOrder utility or directly from the properties window. Completely ignore the TabStop property of containers, which defaults to false even it's very important.
Repeat step 1 with each container.
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.