<p>When creating scrollable user controls with .NET and WinForms I have repeatedly encountered situations where, for example, a vertical scrollbar pops up, overlapping the control's content, causing a horizontal scrollbar to also be needed.  Ideally the content would shrink just a bit to make room for the vertical scrollbar.</p>

<p>My current solution has been to just keep my controls out of the far right 40 pixels or so that the vertical scroll-bar will be taking up.  Since this is still effectively client space for the control, the horizontal scroll-bar still comes up when it gets covered by the vertical scroll-bar, even though no controls are being hidden at all.  But then at least the user doesn't actually need to <strong>use</strong> the horizontal scrollbar that comes up.</p>

<p>Is there a better way to make this all work?  Some way to keep the unneeded and unwanted scrollbars from showing up at all?</p>

[{'answer_id': 26782, 'author': 'Bryan Roth', 'author_id': 299, 'author_profile': 'https://Stackoverflow.com/users/299', 'pm_score': 0, 'selected': False, 'text': '<p>If your controls are inside a panel, try setting the AutoScroll property of the Panel to False.  This will hide the scrollbars.  I hope this points you in the right direction.</p>\n\n<pre><code>myPanel.AutoScroll = False\n</code></pre>\n'}, {'answer_id': 27032, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': True, 'text': '<p>You will need your controls to resize slightly to accommodate the width of the vertical scroll bar. One way to achieve this achieved through docking. Rather than just dropping controls on the form, you\'ll have to play a bit with panels, padding, min/max sizing and docking.</p>\n\n<p>Here is example code you can place behind a blank new Form1. Resize the form, in designer or runtime and you\'ll see that the horizontal scrollbar is not shown and the fields are not overlapped. I\'ve also given the fields a max width for good measure : </p>\n\n<pre><code>#region Windows Form Designer generated code\n\n    /// &lt;summary&gt;\n    /// Required method for Designer support - do not modify\n    /// the contents of this method with the code editor.\n    /// &lt;/summary&gt;\n    private void InitializeComponent() {\n        this.textBox1 = new System.Windows.Forms.TextBox();\n        this.label1 = new System.Windows.Forms.Label();\n        this.panel1 = new System.Windows.Forms.Panel();\n        this.panel2 = new System.Windows.Forms.Panel();\n        this.textBox2 = new System.Windows.Forms.TextBox();\n        this.label2 = new System.Windows.Forms.Label();\n        this.panel1.SuspendLayout();\n        this.panel2.SuspendLayout();\n        this.SuspendLayout();\n        // \n        // textBox1\n        // \n        this.textBox1.Dock = System.Windows.Forms.DockStyle.Top;\n        this.textBox1.Location = new System.Drawing.Point(32, 0);\n        this.textBox1.MaximumSize = new System.Drawing.Size(250, 0);\n        this.textBox1.Name = "textBox1";\n        this.textBox1.Size = new System.Drawing.Size(250, 20);\n        this.textBox1.TabIndex = 0;\n        // \n        // label1\n        // \n        this.label1.AutoSize = true;\n        this.label1.Dock = System.Windows.Forms.DockStyle.Left;\n        this.label1.Location = new System.Drawing.Point(0, 0);\n        this.label1.Name = "label1";\n        this.label1.Padding = new System.Windows.Forms.Padding(0, 3, 0, 0);\n        this.label1.Size = new System.Drawing.Size(32, 16);\n        this.label1.TabIndex = 0;\n        this.label1.Text = "Field:";\n        // \n        // panel1\n        // \n        this.panel1.Controls.Add(this.textBox1);\n        this.panel1.Controls.Add(this.label1);\n        this.panel1.Dock = System.Windows.Forms.DockStyle.Top;\n        this.panel1.Location = new System.Drawing.Point(0, 0);\n        this.panel1.Name = "panel1";\n        this.panel1.Size = new System.Drawing.Size(392, 37);\n        this.panel1.TabIndex = 2;\n        // \n        // panel2\n        // \n        this.panel2.Controls.Add(this.textBox2);\n        this.panel2.Controls.Add(this.label2);\n        this.panel2.Dock = System.Windows.Forms.DockStyle.Top;\n        this.panel2.Location = new System.Drawing.Point(0, 37);\n        this.panel2.Name = "panel2";\n        this.panel2.Size = new System.Drawing.Size(392, 37);\n        this.panel2.TabIndex = 3;\n        // \n        // textBox2\n        // \n        this.textBox2.Dock = System.Windows.Forms.DockStyle.Top;\n        this.textBox2.Location = new System.Drawing.Point(32, 0);\n        this.textBox2.MaximumSize = new System.Drawing.Size(250, 0);\n        this.textBox2.Name = "textBox2";\n        this.textBox2.Size = new System.Drawing.Size(250, 20);\n        this.textBox2.TabIndex = 0;\n        // \n        // label2\n        // \n        this.label2.AutoSize = true;\n        this.label2.Dock = System.Windows.Forms.DockStyle.Left;\n        this.label2.Location = new System.Drawing.Point(0, 0);\n        this.label2.Name = "label2";\n        this.label2.Padding = new System.Windows.Forms.Padding(0, 3, 0, 0);\n        this.label2.Size = new System.Drawing.Size(32, 16);\n        this.label2.TabIndex = 0;\n        this.label2.Text = "Field:";\n        // \n        // Form1\n        // \n        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);\n        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;\n        this.AutoScroll = true;\n        this.ClientSize = new System.Drawing.Size(392, 116);\n        this.Controls.Add(this.panel2);\n        this.Controls.Add(this.panel1);\n        this.Name = "Form1";\n        this.Text = "Form1";\n        this.panel1.ResumeLayout(false);\n        this.panel1.PerformLayout();\n        this.panel2.ResumeLayout(false);\n        this.panel2.PerformLayout();\n        this.ResumeLayout(false);\n\n    }\n\n    #endregion\n\n    private System.Windows.Forms.TextBox textBox1;\n    private System.Windows.Forms.Label label1;\n    private System.Windows.Forms.Panel panel1;\n    private System.Windows.Forms.Panel panel2;\n    private System.Windows.Forms.TextBox textBox2;\n    private System.Windows.Forms.Label label2;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/26721', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2729/']