Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Border to WebBrowser control

Tags:

c#

winforms

When I add a WebBrowser control on my TabPage, it doesn't have a border. I can't find a BorderStyle attribute. How do get the control to have a border? (3D, sunken, whatever)

Screenshot

Only by the scrollbar on the right you see there's actually a control there...

like image 521
Pygmy Avatar asked Dec 10 '09 00:12

Pygmy


2 Answers

Gumpy comments, not accurate. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of your toolbar onto your form.

using System;
using System.Windows.Forms;

class MyWebBrowser : WebBrowser {
  protected override CreateParams CreateParams {
    get {
      var parms = base.CreateParams;
      parms.Style |= 0x800000;  // Turn on WS_BORDER
      return parms;
    }
  }
}

The other border styles work too, check out WinUser.h in the SDK.

like image 65
Hans Passant Avatar answered Sep 22 '22 06:09

Hans Passant


You can wrap the WebBrowser control in a Panel and set the Panel.BorderStyle property.

Panel panel1 = new Panel();
panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
panel1.Controls.Add(webbrowser1);
like image 26
dtb Avatar answered Sep 24 '22 06:09

dtb