Hi all,
Can anybody tell me hoe to resize a control to fit the width of the window when its resized. I'm trying to fit a webbrowser control and the panel its on to the width of the window if its resized.

Dave

Use the docking property. Set the DockStyle = DockStyle.Fill;

Scott,
I am informed through a build error that the webbrowser object does not have a dockstyle property. The only similar one in the properties list is dock.

Dave

That is the one I meant.... set the property in the designer, not in code.

Scott,
I dont see a DockStyle property in the designer? Can you be a little more specific.

Dave

Use the "dock" property. You set webBrowser.Dock = DockStyle.Fill;

Scott,
I found the fill property - the sqaure in the middle of the drop-down box - that was the missing piece of information. But now it expands to fill the entire tab that it is on - covering all the other controls. I need it to stay where it is - relative to its top left corner and resize from there, moving the position of the bottom right corner as I drag out the forms right and lower edges.

Dave

Unset the fill property and set the Anchor property Left, Top, Bottom, and Right.

See the attached project

Form1.Designer.cs :

namespace fitwebbrowserindinwindow
{
	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()
		{
			this.webBrowser1 = new System.Windows.Forms.WebBrowser();
			this.SuspendLayout();
			// 
			// webBrowser1
			// 
			this.webBrowser1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
							| System.Windows.Forms.AnchorStyles.Right)));
			this.webBrowser1.Location = new System.Drawing.Point(-2, 129);
			this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
			this.webBrowser1.Name = "webBrowser1";
			this.webBrowser1.Size = new System.Drawing.Size(620, 250);
			this.webBrowser1.TabIndex = 0;
			this.webBrowser1.Url = new System.Uri("http://www.google.com", System.UriKind.Absolute);
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(618, 379);
			this.Controls.Add(this.webBrowser1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}

		#endregion

		private System.Windows.Forms.WebBrowser webBrowser1;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.