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;
Related
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;
I have set this flowLayoutPanel, the controls inside arrange well, till the last arrives to the bottom border of the panel, then the controls start arranging on the right side (forming another column) keepping the vertical flow. I just want one column.
this.panel.Anchor =
((System.Windows.Forms.AnchorStyles)
(((System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Bottom)| System.Windows.Forms.AnchorStyles.Right)));
this.panel.AutoScroll = true;
this.panel.BorderStyle = BorderStyle.None;
this.panel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.panel.Location = new System.Drawing.Point(0, 184);
this.panel.Name = "myPanel";
this.panel.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.panel.Size = new System.Drawing.Size(300, 371);
this.panel.TabIndex = 9;
Use
this.panel.FlowDirection = System.Windows.Forms.FlowDirection.LeftToRight;
instead of
this.panel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
if you want only one column than please add below code to your application just after control added to your flowlayoutpanel
this.panel.SetFlowBreak(<<YOUR_ADDED_CONTROL_NAME>>, true);
Example
Button btn1 = new Button();
btn1.Text = "TEST";
btn1.Height = 30;
btn1.Width = 100;
this.panel.Controls.Add(btn1);
this.panel.SetFlowBreak(btn1, true);
I want to add some buttons during run time to a existing panel in my form so that I can scroll them by my panel when the number of the buttons increases and they do not fit the form.
I use the this.panel1.Controls.Add(this.button50[number]); but it does not show the button on the panel
How can I show the control on the panel after adding it?
Here is my code:
static int number = 49;
static int size = 163;
public void initialize()
{
this.button50= new System.Windows.Forms.Button[50];
}
public void makeButton()
{
if (number > 0)
{
this.button50[number] = new System.Windows.Forms.Button();
this.button50[number].Font = new System.Drawing.Font("Nazanin"
,12F,System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((byte)(178)));
size = 41 + size;
this.button50[number].Location = new System.Drawing.Point(194, size);
this.button50[number].Name = "buttonPlus"+number;
this.button50[number].Size = new System.Drawing.Size(151, 34);
this.button50[number].TabIndex = 24;
this.button50[number].Text = "انتخاب دستی دروس";
this.button50[number].UseVisualStyleBackColor = true;
this.panel1.Controls.Add(this.button50[number]);
number--;
}
}
//// a part of InitializeComponent() function
//
// panel1
//
this.panel1.Controls.Add(this.button50[number]);
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.button10);
this.panel1.Controls.Add(this.button3);
this.panel1.Controls.Add(this.button8);
this.panel1.Controls.Add(this.button9);
this.panel1.Controls.Add(this.button5);
this.panel1.Controls.Add(this.button7);
this.panel1.Controls.Add(this.button6);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.button4);
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.bindingNavigator1);
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.lable4);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(549, 306);
this.panel1.TabIndex = 0;
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.