I created a window containing 1 flowlayoutpanel and panel.
When I enlarge the size of the window, the flowlayoutpanel changes with the window but the panel doesn't change with the flowlayoutpanel.
I'm having a problem that the panel doesn't automatically adjust its size when resize flowlayoutpanel.
this is code :
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.flowLayoutPanel1.BackColor = System.Drawing.Color.LightBlue;
this.flowLayoutPanel1.Controls.Add(this.pnl_1);
this.flowLayoutPanel1.Controls.Add(this.panel1);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanel1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.flowLayoutPanel1.Size = new System.Drawing.Size(666, 545);
this.flowLayoutPanel1.TabIndex = 1;
this.flowLayoutPanel1.WrapContents = false;
//
// pnl_1
//
this.pnl_1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.pnl_1.BackColor = System.Drawing.Color.Azure;
this.pnl_1.Controls.Add(this.txt_input1_3);
this.pnl_1.Controls.Add(this.txt_associated1_3);
this.pnl_1.Controls.Add(this.txt_input1_2);
this.pnl_1.Controls.Add(this.txt_input1_1);
this.pnl_1.Controls.Add(this.txt_associated1_2);
this.pnl_1.Controls.Add(this.txt_associated1_1);
this.pnl_1.Controls.Add(this.txt_field_1);
this.pnl_1.Controls.Add(this.lb_field1);
this.pnl_1.Controls.Add(this.lb_input1);
this.pnl_1.Controls.Add(this.lb_associal1);
this.pnl_1.Location = new System.Drawing.Point(3, 3);
this.pnl_1.Name = "pnl_1";
this.pnl_1.Size = new System.Drawing.Size(663, 113);
this.pnl_1.TabIndex = 0;
Related
I am trying to set my panel so it will scroll horizontally. I have tried:
MainPanel.HorizontalScroll.Enabled = true;
MainPanel.HorizontalScroll.Visible = true;
MainPanel.VerticalScroll.Enabled = false;
MainPanel.VerticalScroll.Visible = false;
My MainPanel is a parent to 2 sub Panels that are Horizontaly larger than the Panel itself but the horizontal scroll bar still doesn't appear. How can I fix this?
This is the code in the .Designer.cs file of the Parent Form of my Panels:
this.panel0.Dock = System.Windows.Forms.DockStyle.Top;
this.panel0.Location = new System.Drawing.Point(0, 0);
this.panel0.Name = "panel0";
this.panel0.Size = new System.Drawing.Size(828, 28);
this.panel0.TabIndex = 2;
//
// list
//
this.list.Dock = System.Windows.Forms.DockStyle.Fill;
this.list.Location = new System.Drawing.Point(0, 28);
this.list.Name = "list";
this.list.Size = new System.Drawing.Size(828, 444);
this.list.TabIndex = 3;
//
// MainPanel
//
this.MainPanel.AutoScroll = true;
this.MainPanel.Controls.Add(this.list);
this.MainPanel.Controls.Add(this.panel0);
this.MainPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.MainPanel.Location = new System.Drawing.Point(152, 104);
this.MainPanel.Name = "MainPanel";
this.MainPanel.Size = new System.Drawing.Size(828, 472);
this.MainPanel.TabIndex = 7;
I want put a bunch of buttons at the top section of my form, and a SplitContainer right below these buttons. All these are done in the code (not thru the designer), so I can manage the number and text of the buttons dynamically. I reckon it is handy to put the button into a FlowLayoutPanel, so they can response with the flow feature when the form gets resized.
My question is how do I set up the SplitContainer layout settings (size, location, anchor, docking etc.), to make sure no matter how I resize the form, the SplitContainer is right below the buttons (no gap), and it fills up the rest of the form. Below is what I've done.
this.Size = new Size(300, 400);
string[] tags = new string[] { "action", "romance", "drama", "sci-fi", "horror" };
FlowLayoutPanel flp = new FlowLayoutPanel();
flp.Size = new Size(this.Width, 50);
flp.Location = new Point(0, 0);
flp.AutoSize = true;
flp.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
flp.FlowDirection = FlowDirection.LeftToRight;
this.Controls.Add(flp);
//flp.Resize += flp_Resize;
foreach (string tag in tags)
{
Button btn = new Button();
btn.Text = tag;
flp.Controls.Add(btn);
}
SplitContainer sc = new SplitContainer();
ListBox lb = new ListBox(); lb.Dock = DockStyle.Fill; lb.Parent = sc.Panel1; lb.Items.Add("test");
PictureBox pb = new PictureBox(); pb.Dock = DockStyle.Fill; pb.Parent = sc.Panel2; pb.BackColor = Color.LightBlue;
sc.Size = new Size(this.Width, this.Height-flp.Height);
sc.Location = new Point(0, flp.Height);
sc.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
this.Controls.Add(sc);
Here is the solution. Thanks to #Fabio.
this.Size = new Size(300, 400);
TableLayoutPanel tlp = new TableLayoutPanel();
tlp.RowCount = 2;
tlp.ColumnCount = 1;
tlp.Dock = DockStyle.Fill;
this.Controls.Add(tlp);
string[] tags = new string[] { "action", "romance", "drama", "sci-fi", "horror" };
FlowLayoutPanel flp = new FlowLayoutPanel();
flp.AutoSize = true;
flp.Dock = DockStyle.Fill;
flp.BackColor = Color.LightCyan;
flp.FlowDirection = FlowDirection.LeftToRight;
tlp.Controls.Add(flp, 0, 0);
foreach (string tag in tags)
{
Button btn = new Button();
btn.Text = tag;
flp.Controls.Add(btn);
}
SplitContainer sc = new SplitContainer();
ListBox lb = new ListBox(); lb.Dock = DockStyle.Fill; lb.Parent = sc.Panel1; lb.Items.Add("test");
PictureBox pb = new PictureBox(); pb.Dock = DockStyle.Fill; pb.Parent = sc.Panel2; pb.BackColor = Color.LightBlue;
sc.Dock = DockStyle.Fill;
tlp.Controls.Add(sc,0,1);
I have ma de a winform, that contains a tabControl (3 tabs, maybe more later).
In 2 of my tabs, I got a listBoxView.
The problem is, when I click on fullSize button, the tabControl doesn't change his size. That makes an awful window.
How can I define dynamic size of my tabControl, based on the winforms border size, and a dynamic size of my listBoxView based on tabControl size?
TabControl must adapt to form size, then pages in tabControl must adapt to tabControl size, and then, listBox in the pages must adapt to its pages size.
Here is the form :
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1313, 614);
this.Controls.Add(this.tabControl1);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgCSV)).EndInit();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.ResumeLayout(false);
And the tabControl with one of his pages :
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Location = new System.Drawing.Point(13, 13);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1288, 589);
this.tabControl1.TabIndex = 0;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.listBoxFiles);
this.tabPage2.Controls.Add(this.richTextBox1);
this.tabPage2.Controls.Add(this.buttonBottom);
this.tabPage2.Controls.Add(this.buttonFront);
this.tabPage2.Controls.Add(this.buttonDown);
this.tabPage2.Controls.Add(this.buttonUp);
this.tabPage2.Controls.Add(this.label2);
this.tabPage2.Location = new System.Drawing.Point(4, 25);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(1280, 560);
this.tabPage2.TabIndex = 1;
this.tabPage2.UseVisualStyleBackColor = true;
I tried with Parent.width, ClientRectangle, ClientSize.
I'm lost with all this properties and no one is successfull...
After trippino answer :
Indeed, a dock on the tabControl will resize him, but I can't do it on a listBoxView, because one of the element will just take all the page.
And Anchor do not resize elements, it will juste reorganise them to fit in the page.
Still not resizing like this :
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1313, 614);
this.tabControl1.TabIndex = 0;
//
// listBoxFiles
//
this.listBoxFiles.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.listBoxFiles.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.listBoxFiles.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.listBoxFiles.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.listBoxFiles.FormattingEnabled = true;
this.listBoxFiles.ItemHeight = 16;
this.listBoxFiles.Location = new System.Drawing.Point(185, 43);
this.listBoxFiles.Name = "listBoxFiles";
this.listBoxFiles.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.listBoxFiles.Size = new System.Drawing.Size(1040, 244);
this.listBoxFiles.TabIndex = 42;
private void tabPage2_SizeChanged(object sender, EventArgs e)
{
this.buttonAucun.Location = new System.Drawing.Point(this.buttonAucun.Location.X, this.listBoxFiles.Location.Y + this.listBoxFiles.Height + 10);
this.progressBar1.Location = new System.Drawing.Point(this.progressBar1.Location.X, this.buttonAucun.Location.Y + this.buttonAucun.Height + 10);
this.richTextBox1.Location = new System.Drawing.Point(this.richTextBox1.Location.X, this.progressBar1.Location.Y + this.progressBar1.Height + 10);
this.buttonEnregistrer.Location = new System.Drawing.Point(this.buttonEnregistrer.Location.X, this.richTextBox1.Location.Y + this.richTextBox1.Height + 10);
}
Since, buttonEnregistrer is on the bottom of my tabPage, I also tried :
this.buttonEnregistrer.Location = new System.Drawing.Point(this.buttonEnregistrer.Location.X, this.tabPage2.Height -50);
But his will not retake it's original location.
Thank you.
Just use the Dock property of the tabControl setting it to Fill. It should solve your issue.
MSDN Dock Property reference
EDIT AFTER DISCUSSION: to anchor 4 sides you have to use :
this.listBoxFiles.Anchor = ((System.Windows.Forms.AnchorStyles
((((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
I have included 4 buttons inside a panel. The panel is docked to the main window.
When I resize the main window, it doesn't reposition the 4 buttons with respect to the newly modified window size. I am using VS 2010 Designer view to accomplish this.
Here is the entire code generated from designer.cs
private void InitializeComponent()
{
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.TreeDDC = new System.Windows.Forms.TreeView();
this.BtnPointCtrl = new System.Windows.Forms.Button();
this.BtnLogic = new System.Windows.Forms.Button();
this.BtnComm = new System.Windows.Forms.Button();
this.BtnSystem = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.statusStrip1.SuspendLayout();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1});
this.statusStrip1.Location = new System.Drawing.Point(0, 445);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(639, 22);
this.statusStrip1.TabIndex = 0;
this.statusStrip1.Text = "statusBar";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(61, 17);
this.toolStripStatusLabel1.Text = "Status Bar";
//
// TreeDDC
//
this.TreeDDC.Dock = System.Windows.Forms.DockStyle.Left;
this.TreeDDC.Location = new System.Drawing.Point(0, 0);
this.TreeDDC.Name = "TreeDDC";
this.TreeDDC.Size = new System.Drawing.Size(97, 445);
this.TreeDDC.TabIndex = 1;
//
// BtnPointCtrl
//
this.BtnPointCtrl.Location = new System.Drawing.Point(28, 93);
this.BtnPointCtrl.Name = "BtnPointCtrl";
this.BtnPointCtrl.Size = new System.Drawing.Size(202, 86);
this.BtnPointCtrl.TabIndex = 2;
this.BtnPointCtrl.Text = "???";
this.BtnPointCtrl.UseVisualStyleBackColor = true;
//
// BtnLogic
//
this.BtnLogic.Location = new System.Drawing.Point(28, 282);
this.BtnLogic.Name = "BtnLogic";
this.BtnLogic.Size = new System.Drawing.Size(202, 86);
this.BtnLogic.TabIndex = 4;
this.BtnLogic.Text = "??";
this.BtnLogic.UseVisualStyleBackColor = true;
//
// BtnComm
//
this.BtnComm.Location = new System.Drawing.Point(307, 93);
this.BtnComm.Name = "BtnComm";
this.BtnComm.Size = new System.Drawing.Size(202, 86);
this.BtnComm.TabIndex = 3;
this.BtnComm.Text = "??";
this.BtnComm.UseVisualStyleBackColor = true;
//
// BtnSystem
//
this.BtnSystem.Location = new System.Drawing.Point(307, 282);
this.BtnSystem.Name = "BtnSystem";
this.BtnSystem.Size = new System.Drawing.Size(202, 86);
this.BtnSystem.TabIndex = 5;
this.BtnSystem.Text = "???";
this.BtnSystem.UseVisualStyleBackColor = true;
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.BtnSystem);
this.panel1.Controls.Add(this.BtnComm);
this.panel1.Controls.Add(this.BtnPointCtrl);
this.panel1.Controls.Add(this.BtnLogic);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(97, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(542, 445);
this.panel1.TabIndex = 6;
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(639, 467);
this.Controls.Add(this.panel1);
this.Controls.Add(this.TreeDDC);
this.Controls.Add(this.statusStrip1);
this.Name = "MainForm";
this.Text = "MainForm";
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
But I believe the only code of interest will be the following:
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Controls.Add(this.BtnSystem);
this.panel1.Controls.Add(this.BtnComm);
this.panel1.Controls.Add(this.BtnPointCtrl);
this.panel1.Controls.Add(this.BtnLogic);
Any help will be greatly appreciated.
Use the Anchor property of the buttons...
Read it Working with Anchoring and Docking
The Panel does not itself repositioning the controls when it resizing, Use the Anchor (Top, Bottom, Left, Right) property that the controls reposition when parent Panel resizes...
Or Use TableLayOutPanel.
Docking the panel will only resize the panel iteelf, not reposition the controls within the panel. To have elements within a container change their position after resizing the container, look into the Anchor property. There is also TableLayoutPanel which can, as its name suggests, layout controls in a table format.
Please Dock a FlowLayoutPanel inside your panel and palce the buttons inside that FlowLayoutPanel. Set the Layout Direction property. Now when you resize the main window your buttons will also be resized.
I have a child panel in a form which contains some text boxes and buttons. I tried setting tabstop and tabindex properties for these controls so that the user can tab from one control to the next. But for some reason the tabbing does not work, the curor stays on the same field which has the focus when I press the tab key. I am using C# with .Net 3.5 framework. Below is how my code looks like -
rightPanel.Controls.Clear();
marketMessageLabel = new Label();
marketMessageLabel.Location = new Point(0, 20);
marketMessageLabel.AutoSize = false;
marketMessageLabel.Size = new Size(rightPanel.Width, 42);
marketMessageLabel.BackColor = Color.White;
marketMessageLabel.Font = new System.Drawing.Font("Verdana", 8.00F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
rightPanel.Controls.Add(marketMessageLabel);
signinUserNameLabel = new Label();
signinUserNameLabel.Location = new Point(0, 150);
signinUserNameLabel.Size = new Size(60, 14);
signinUserNameLabel.BackColor = Color.White;
signinUserNameLabel.Text = "User Name";
signinUserNameLabel.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
rightPanel.Controls.Add(signinUserNameLabel);
signinUserNameTextBox = new TextBox();
signinUserNameTextBox.Location = new Point(0, 170);
signinUserNameTextBox.Width = this.Width - 80;
signinUserNameTextBox.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
signinUserNameTextBox.TabIndex = 0;
signinUserNameTextBox.TabStop = true;
rightPanel.Controls.Add(signinUserNameTextBox);
signinPasswordLabel = new Label();
signinPasswordLabel.Location = new Point(0, 192);
signinPasswordLabel.Size = new Size(100, 14);
signinPasswordLabel.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
signinPasswordLabel.BackColor = Color.White;
signinPasswordLabel.Text = "Password";
rightPanel.Controls.Add(signinPasswordLabel);
signinPasswordTextBox = new TextBox();
signinPasswordTextBox.Location = new Point(0, 210);
signinPasswordTextBox.Width = this.Width - 80;
signinPasswordTextBox.PasswordChar = '*';
signinPasswordTextBox.TabIndex = 1;
signinPasswordTextBox.TabStop = true;
rightPanel.Controls.Add(signinPasswordTextBox);
signInButton = new Button();
signInButton.Text = "Sign In";
signInButton.Font = new System.Drawing.Font("Verdana", 9.00F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
signInButton.Width = 70;
signInButton.BackColor = Color.White;
signInButton.Location = new Point(0,240);
signInButton.Click += new EventHandler(signInButton_Click);
signInButton.TabIndex = 2;
signInButton.TabStop = true;
rightPanel.Controls.Add(signInButton);
Another possible problem is if the form where the "tabbing" does not work is on a form that is not displayed modally.
For some reasons, "tabbing" sometimes does not work if a child form is displayed with .show, and you'd rather display the form with .ShowDialog.
If the form is modeless (displayed with .Show()), then you need to add the following code to handle the keyDown event:
private void YourForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Tab)
{
if (e.Modifiers == Keys.Shift)
this.ProcessTabKey(false);
else
this.ProcessTabKey(true);
}
}
You also need to set the KeyPreview property to True.
The solution is setting TabStop = true on the panel.
I just ran a little test, and it seems that winforms won't tab into the child panel if there are no other focusable controls outside of the panel.
You won't actually end up tabbing "onto" the panel, but it gets you around this issue you're seeing and it will tab to it's first child control.
Make sure you set the tabindex for the labels also, despite it is not focusable.
From VS designer window, with your form on the screen in design more, click on
View Menu
Tab Order menu option
point and click to set the sequential order of the controls (including labels).
Hope this helps,
Best regards,
Tom.