Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overlapping components with form designer

Status
Not open for further replies.

Echilon

Programmer
Feb 22, 2007
54
0
0
GB
I'm trying to create an application in C# using the forms designer in Visual Studio 2008. Coming from Java, it's a welcome relief not to have to hand code the whole layout, but there's something that doesn't seem to be working. The 'Dock' setting for components. I have a split pane, inside each pane of which are two more split panes. Whenever I set the main split pain to dock horizontally and vertically (the middle button in the designer), it underlaps the toolbar, and the same happens in the sub-panes - they overlap the drop down box I've set to dock at the top.

Is it best to have just one docking component per panel or is there a way around this? The window looks fine at the default size, but once it's resized nothing changes size to fit.

The code from the designer is at if anyone could take a look and see if I'm doing something wrong. It's probably something simple, but maybe someone else has had a similar problem.

Thanks.
 
Docking can be problematic (or at least annoying). The trick is to place the components on the form in the correct order.

Code:
namespace WindowsFormsApplication2
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
			this.menuStrip1 = new System.Windows.Forms.MenuStrip();
			this.toolStrip1 = new System.Windows.Forms.ToolStrip();
			this.splitContainer1 = new System.Windows.Forms.SplitContainer();
			this.splitContainer2 = new System.Windows.Forms.SplitContainer();
			this.statusStrip1 = new System.Windows.Forms.StatusStrip();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.splitContainer3 = new System.Windows.Forms.SplitContainer();
			this.statusStrip2 = new System.Windows.Forms.StatusStrip();
			this.comboBox2 = new System.Windows.Forms.ComboBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.richTextBox1 = new System.Windows.Forms.RichTextBox();
			this.listView1 = new System.Windows.Forms.ListView();
			this.listView2 = new System.Windows.Forms.ListView();
			this.menuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
			this.menuItemToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
			this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
			this.toolStripItemToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
			this.menuStrip1.SuspendLayout();
			this.toolStrip1.SuspendLayout();
			this.splitContainer1.Panel1.SuspendLayout();
			this.splitContainer1.Panel2.SuspendLayout();
			this.splitContainer1.SuspendLayout();
			this.splitContainer2.Panel1.SuspendLayout();
			this.splitContainer2.Panel2.SuspendLayout();
			this.splitContainer2.SuspendLayout();
			this.splitContainer3.Panel1.SuspendLayout();
			this.splitContainer3.Panel2.SuspendLayout();
			this.splitContainer3.SuspendLayout();
			this.SuspendLayout();
			// 
			// menuStrip1
			// 
			this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.menuItemToolStripMenuItem});
			this.menuStrip1.Location = new System.Drawing.Point(0, 0);
			this.menuStrip1.Name = "menuStrip1";
			this.menuStrip1.Size = new System.Drawing.Size(962, 24);
			this.menuStrip1.TabIndex = 0;
			this.menuStrip1.Text = "menuStrip1";
			// 
			// toolStrip1
			// 
			this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripDropDownButton1});
			this.toolStrip1.Location = new System.Drawing.Point(0, 24);
			this.toolStrip1.Name = "toolStrip1";
			this.toolStrip1.Size = new System.Drawing.Size(962, 25);
			this.toolStrip1.TabIndex = 1;
			this.toolStrip1.Text = "toolStrip1";
			// 
			// splitContainer1
			// 
			this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.splitContainer1.Location = new System.Drawing.Point(0, 49);
			this.splitContainer1.Name = "splitContainer1";
			// 
			// splitContainer1.Panel1
			// 
			this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
			this.splitContainer1.Panel1.Controls.Add(this.statusStrip1);
			this.splitContainer1.Panel1.Controls.Add(this.comboBox1);
			// 
			// splitContainer1.Panel2
			// 
			this.splitContainer1.Panel2.Controls.Add(this.splitContainer3);
			this.splitContainer1.Panel2.Controls.Add(this.statusStrip2);
			this.splitContainer1.Panel2.Controls.Add(this.comboBox2);
			this.splitContainer1.Size = new System.Drawing.Size(962, 412);
			this.splitContainer1.SplitterDistance = 477;
			this.splitContainer1.TabIndex = 2;
			// 
			// splitContainer2
			// 
			this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
			this.splitContainer2.Location = new System.Drawing.Point(0, 21);
			this.splitContainer2.Name = "splitContainer2";
			this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
			// 
			// splitContainer2.Panel1
			// 
			this.splitContainer2.Panel1.BackColor = System.Drawing.SystemColors.Window;
			this.splitContainer2.Panel1.Controls.Add(this.listView1);
			// 
			// splitContainer2.Panel2
			// 
			this.splitContainer2.Panel2.BackColor = System.Drawing.SystemColors.Window;
			this.splitContainer2.Panel2.Controls.Add(this.textBox1);
			this.splitContainer2.Size = new System.Drawing.Size(477, 369);
			this.splitContainer2.SplitterDistance = 171;
			this.splitContainer2.TabIndex = 2;
			// 
			// statusStrip1
			// 
			this.statusStrip1.Location = new System.Drawing.Point(0, 390);
			this.statusStrip1.Name = "statusStrip1";
			this.statusStrip1.Size = new System.Drawing.Size(477, 22);
			this.statusStrip1.TabIndex = 1;
			this.statusStrip1.Text = "statusStrip1";
			// 
			// comboBox1
			// 
			this.comboBox1.Dock = System.Windows.Forms.DockStyle.Top;
			this.comboBox1.FormattingEnabled = true;
			this.comboBox1.Location = new System.Drawing.Point(0, 0);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(477, 21);
			this.comboBox1.TabIndex = 0;
			// 
			// splitContainer3
			// 
			this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill;
			this.splitContainer3.Location = new System.Drawing.Point(0, 21);
			this.splitContainer3.Name = "splitContainer3";
			this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;
			// 
			// splitContainer3.Panel1
			// 
			this.splitContainer3.Panel1.BackColor = System.Drawing.SystemColors.Window;
			this.splitContainer3.Panel1.Controls.Add(this.listView2);
			// 
			// splitContainer3.Panel2
			// 
			this.splitContainer3.Panel2.BackColor = System.Drawing.SystemColors.Window;
			this.splitContainer3.Panel2.Controls.Add(this.richTextBox1);
			this.splitContainer3.Size = new System.Drawing.Size(481, 369);
			this.splitContainer3.SplitterDistance = 172;
			this.splitContainer3.TabIndex = 2;
			// 
			// statusStrip2
			// 
			this.statusStrip2.Location = new System.Drawing.Point(0, 390);
			this.statusStrip2.Name = "statusStrip2";
			this.statusStrip2.Size = new System.Drawing.Size(481, 22);
			this.statusStrip2.TabIndex = 1;
			this.statusStrip2.Text = "statusStrip2";
			// 
			// comboBox2
			// 
			this.comboBox2.Dock = System.Windows.Forms.DockStyle.Top;
			this.comboBox2.FormattingEnabled = true;
			this.comboBox2.Location = new System.Drawing.Point(0, 0);
			this.comboBox2.Name = "comboBox2";
			this.comboBox2.Size = new System.Drawing.Size(481, 21);
			this.comboBox2.TabIndex = 0;
			// 
			// textBox1
			// 
			this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.textBox1.Location = new System.Drawing.Point(0, 0);
			this.textBox1.Multiline = true;
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(477, 194);
			this.textBox1.TabIndex = 0;
			// 
			// richTextBox1
			// 
			this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.richTextBox1.Location = new System.Drawing.Point(0, 0);
			this.richTextBox1.Name = "richTextBox1";
			this.richTextBox1.Size = new System.Drawing.Size(481, 193);
			this.richTextBox1.TabIndex = 0;
			this.richTextBox1.Text = "";
			// 
			// listView1
			// 
			this.listView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.listView1.Location = new System.Drawing.Point(0, 0);
			this.listView1.Name = "listView1";
			this.listView1.Size = new System.Drawing.Size(477, 171);
			this.listView1.TabIndex = 0;
			this.listView1.UseCompatibleStateImageBehavior = false;
			// 
			// listView2
			// 
			this.listView2.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.listView2.Dock = System.Windows.Forms.DockStyle.Fill;
			this.listView2.Location = new System.Drawing.Point(0, 0);
			this.listView2.Name = "listView2";
			this.listView2.Size = new System.Drawing.Size(481, 172);
			this.listView2.TabIndex = 0;
			this.listView2.UseCompatibleStateImageBehavior = false;
			// 
			// menuItemToolStripMenuItem
			// 
			this.menuItemToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.menuItemToolStripMenuItem1});
			this.menuItemToolStripMenuItem.Name = "menuItemToolStripMenuItem";
			this.menuItemToolStripMenuItem.Size = new System.Drawing.Size(77, 20);
			this.menuItemToolStripMenuItem.Text = "Menu Item";
			// 
			// menuItemToolStripMenuItem1
			// 
			this.menuItemToolStripMenuItem1.Name = "menuItemToolStripMenuItem1";
			this.menuItemToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
			this.menuItemToolStripMenuItem1.Text = "Menu Item 1";
			// 
			// toolStripDropDownButton1
			// 
			this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
			this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripItemToolStripMenuItem1});
			this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));
			this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
			this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
			this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 22);
			this.toolStripDropDownButton1.Text = "toolStripDropDownButton1";
			// 
			// toolStripItemToolStripMenuItem1
			// 
			this.toolStripItemToolStripMenuItem1.Name = "toolStripItemToolStripMenuItem1";
			this.toolStripItemToolStripMenuItem1.Size = new System.Drawing.Size(152, 22);
			this.toolStripItemToolStripMenuItem1.Text = "ToolStrip Item";
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(962, 461);
			this.Controls.Add(this.splitContainer1);
			this.Controls.Add(this.toolStrip1);
			this.Controls.Add(this.menuStrip1);
			this.MainMenuStrip = this.menuStrip1;
			this.Name = "Form1";
			this.Text = "Form1";
			this.menuStrip1.ResumeLayout(false);
			this.menuStrip1.PerformLayout();
			this.toolStrip1.ResumeLayout(false);
			this.toolStrip1.PerformLayout();
			this.splitContainer1.Panel1.ResumeLayout(false);
			this.splitContainer1.Panel1.PerformLayout();
			this.splitContainer1.Panel2.ResumeLayout(false);
			this.splitContainer1.Panel2.PerformLayout();
			this.splitContainer1.ResumeLayout(false);
			this.splitContainer2.Panel1.ResumeLayout(false);
			this.splitContainer2.Panel2.ResumeLayout(false);
			this.splitContainer2.Panel2.PerformLayout();
			this.splitContainer2.ResumeLayout(false);
			this.splitContainer3.Panel1.ResumeLayout(false);
			this.splitContainer3.Panel2.ResumeLayout(false);
			this.splitContainer3.ResumeLayout(false);
			this.ResumeLayout(false);
			this.PerformLayout();

		}

		#endregion
[b]
		private System.Windows.Forms.MenuStrip menuStrip1;
		private System.Windows.Forms.ToolStrip toolStrip1;
		private System.Windows.Forms.SplitContainer splitContainer1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.SplitContainer splitContainer2;
		private System.Windows.Forms.StatusStrip statusStrip1;
		private System.Windows.Forms.SplitContainer splitContainer3;
		private System.Windows.Forms.StatusStrip statusStrip2;
		private System.Windows.Forms.ComboBox comboBox2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.ListView listView1;
		private System.Windows.Forms.ListView listView2;
		private System.Windows.Forms.RichTextBox richTextBox1;
		private System.Windows.Forms.ToolStripMenuItem menuItemToolStripMenuItem;
		private System.Windows.Forms.ToolStripMenuItem menuItemToolStripMenuItem1;
		private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
		private System.Windows.Forms.ToolStripMenuItem toolStripItemToolStripMenuItem1;
[/b]	}
}


The section at the bottom that I've highlighted shows an order that works.

It really is just a question of being careful.

Hope this helps.

[vampire][bat]
 
I've tried loads of different orders but nothing seems to work. I've even tried adding them to a panel inside the split panel, but that has no effect.
 
earthandfire has shown you the designer code.

DO NOT EDIT THE DESIGNER CODE or you will be in a mess!

Generally, you add any components that you want to dock to a side first, and then add the component that you want to "Fill" with last.


So if I wanted a split panel up and down with the bottom section taking up all the extra space then I would add a panel control to the form, set it to Dock -> Top. Then add a second panel and set it to Dock -> Fill

I tend to put everything in panels as it makes life a lot easier.

 
I've tried undocking the components, then placing a panel in the main form first, then adding the top menu bar, then the split panel, but the split panel still goes underneath the menu. The split panel is set to 'Fill' and the menu is docked at 'Top'. I'm also using the same settings inside the split panel for a drop down box (Dock:top) and a list view (Dock:Fill). Perhaps this picture will explain the problem more:
 
 http://mi6.nu/cs-layout.png
I was not suggesting that the designer code should be edited by hand. The only reason that I poosted the designer code was to enable comparison between the designer code for a layout that works with the designer code for a layout that doesn't work as given in Echilon's first post.

Additionally I highlighted (emboldened) a block of code at the end which shows the order that the elements should be placed on the form.

In summary:
===========
[tt]
Menu[tab]Dock Top
ToolStrip[tab]Dock Top
SplitContainer1[tab]Dock Fill
[tab]ComboBoxes1 and 2[tab]Dock Top
[tab]StatusStrips1 & 2[tab]Dock Bottom
[tab]SplitContainers2 & 3[tab]Dock Fill

and then the ListViews and (Rich)TextBoxes Docked to fill the appropriate regions of SplitContainers2 & 3.
[/tt]

Hope this helps.

[vampire][bat]
 
Thanks!

Eventually, after lots of clicking and dragging, it works. :)
 
For me, I change the z-orders of the controls in the designer to manipulate the orders of which they dock. You can right click them and click Send TO Back or Bring to front to get them in the right order.

As for editing the designer generated code... I do it all the time, its no biggie as long as you know what you are doing. I know it was screwy back in VS 2003, but I have modified it in VS 2005 and 2008 without any problems at all.
 
I assumed the designer code was linked with some sort of meta data somewhere. When I tried to change the text on some buttons, the designer just refused to open the code I'd edited.
 
To be on the safe side, only modify the designer code when the form designer window is closed.

I've done it with it both open and closed without problems, however it may try to refresh the designer layout while your editing the code, which can run into problems.
 
oh and if you do modify the designer code, hit F6 to build and make sure it compiles before opening the design window again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top