WebBrowser control chops off lower 25% of screen

2019-09-04 11:32发布

问题:

This is all there is to my code. I've tried moving the WindowState assignment to the Form1_Load procedure, but that doesn't make any difference.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            WindowState = FormWindowState.Maximized;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Url = new Uri("http://empire.goodgamestudios.com");
        }
    }
}

回答1:

Okay, figured it out!

The problem is:

Your WebBrowser Control is using IE 7(by default) to render the pages, the pages you navigate to.

Solution:

You need the WebBrowser Control to render the pages using the latest version of Internet Explorer (i.e; the latest version installed on your machine..mine one is IE 11) and the problem will be resolved.

As per MSDN, the Value - 11001 (0x2AF9) says:

Internet Explorer 11. Webpages are displayed in IE11 edge mode, regardless of the declared !DOCTYPE directive. Failing to declare a !DOCTYPE directive causes the page to load in Quirks.


Steps:

You need to set the (DWORD) to your application with the value 11001.

For this, navigate to to the registry directory as shown below:

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
   SOFTWARE
      Microsoft
         Internet Explorer
            Main
               FeatureControl
                  FEATURE_BROWSER_EMULATION
                     WebBrowser_Test.vshost.exe = (DWORD) 11001 

Create a new Key and name it as WebBrowser_Test.vshost.exe as shown in the picture below:

Note: Change the prefix WebBrowser_Test as per the name of your application.

Now, add the decimal value 11001 to the Key which you created.

The image below will give a clear representation of what has been said above:

Now, run your app and you should be able to see it that the WebBrowser Control isn't chopped off anymore.