ByronMcGrath
ByronMcGrath

Reputation: 375

C# Web Browser Width

I'm trying to set my width of my WebBrowser in my C# Form but I can't get it to match the Form width, I've searched all through the internet and couldn't find an answer.

p.s. whats the best way to make a navigation bar on a form, im currently using a label and setting its background color but I'd like a better looking one

Many thanks in advance

Upvotes: 0

Views: 1205

Answers (1)

Gareth
Gareth

Reputation: 2791

Couple of possibilities:

a) Manually size the WebBrowser control and drag the width so it matches the width of the form in the designer. Then set the Anchor property so the control is anchored to the sides. To match the width only, you'd set this to:

webBrowser1.Anchor = AnchorStyles.Left | AnchorStyles.Right;

b) Just place the WebBrowser control on the form and set the Dock Property to DockStyle.Fill as suggested in comments above. Note that this will cause it to fill the whole form, and not just the width. This will override any Anchor property you might have set.

webBrowser1.Dock = DockStyle.Fill;

If you use a ToolStrip for your navigation, you can then add a ToolStripButton for each individual navigation function to the ToolStrip, and the IDE makes this easy. If you're going to use it with Anchoring the anchor on the ToolStrip should be also be set to Top.

Personally, I'd go for the Dock option, unless there are other controls on the form which are going to complicate matters from a layout point of view. (Although you can start using splitters in conjuction with Dock but unless you have to - don't go there)

c) Use WPF as the presentation technology instead. This is much better for layout and is the newer technology but if you're not familiar with WPF at all there will be a steeper learning curve to negotiate...

Upvotes: 2

Related Questions