WebBrowser kernel designation

Source: Internet
Author: User

I. BACKGROUND

These days in the maintenance of a project of the company, uh ... To now seven or eight years no one moved (is also old-fashioned), said n years ago code can not touch everywhere is pit can't dig pit still have step by step of pits, just today filled a pit here as a record for later, the code in addition to some do not understand or say is very messy outside, others are ok (no comment, The annotated place is the automatically generated English annotation ..., which contains various delegates, events, multiple threads, user controls, and so on).

Second, the question

is a CS program, which has a function is to enter the URL and then display the content of the Web page, so the problem is many sites do not support IE8 the following kernel browser (very rude jump to the browser download page ~ ~). Then why not webkit the kernel ... Just said it was seven or eight years ago the code ..., with the WebBrowser WebBrowser WebBrowser, said to change a bar time is not allowed and ... You understand ~ ~ (mainly adjusts too much), also can only die horse when live horse medical.

Third, the way to solve

1. Upgrade IE browser

The first thing to think about is to upgrade IE browser, say dry on the dry download and install the latest version of IE browser ... Restart ... Run the program ... Enter URL ... Very rude jump to the browser download page ~ ~, it seems to be too naïve ... originally WebBrowser using the IE7 kernel by default, only upgrade the browser is useless, you need to manually specify

2. Manually specify the WebBrowser core

After browsing a lot of information, we found a solution: Change the Registry

Enter "Regedit.exe" in the Start menu to enter the Registry Editor

Registry key found: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\main\featurecontrol\feature_browser_emulation

Right-click in the blank area on the right and click [New]→[dword (32-bit) value]

The newly created item is named MyApplication.exe, when you edit the value, choose the Radix "decimal", fill in the value data, fill in the 11000 (IE11)

Finally run the MyAplication.exe and find that the problem has been solved

DWORD value corresponding to different versions of IE:

Original: https://msdn.microsoft.com/en-us/library/ee330730 (v=vs.85). Aspx#browser_emulation

But .... It's always a hassle to manually change the registry, so try to use code to solve problems that can be solved with code .

3. Automatically specify the WebBrowser kernel

Idea: Detect IE version, return DWORD value according to different IE version, modify registry

Just stick to the code, there's a note.

Code:

  public class Ieversion {//<summary>//IE webbrowser kernel Settings//</summary> P ublic static void Browseremulationset () {//Current program name var exename = process.getcurrentprocess ().            ProcessName + ". exe";            system registry information var Mreg = Registry.localmachine; ie registry information var ie = Mreg. OpenSubKey (@ "Software\Microsoft\Internet explorer\main\featurecontrol\feature_browser_emulation",            Registrykeypermissioncheck.readwritesubtree); if (ie = null) {try {var val = ieversionemulation (ieversion                    ()); if (val! = 0) {ie.                    SetValue (EXEName, Val); } mreg.                Close (); } catch (Exception ex) {Console.Write (ex.                Message); }}//<summary>       IE version No.//</summary>//<returns></returns> static int ieversion ()            {//ie version number RegistryKey mreg = registry.localmachine; Mreg = Mreg.            CreateSubKey ("Software\\microsoft\\internet explorer"); Updated version var svcversion = Mreg.            GetValue ("Svcversion"); if (svcversion! = null) {Mreg.                Close (); var v = svcversion.tostring (). Split ('. ')                [0]; return int.            Parse (v); } else {//default version var ieversion = Mreg.                GetValue ("Version"); Mreg.                Close (); if (ieversion! = null) {var v = ieversion.tostring (). Split ('. ')                    [0]; return int.                Parse (v);        }} return 0; }///<summary>///emulation values are returned according to IE version number///</summary>//<paraM name= "ieversion" ></param>///<returns></returns> static int ieversionemulation (int i            eversion) {//ie7 7000 (0x1b58) if (Ieversion < 8) {return 0;            } if (ieversion = = 8) {return 0x1f40;//8000 (0X1F40), 8888 (0X22B8)            } if (ieversion = = 9) {return 0x2328;//9000 (0x2328), 9999 (0x270f)}            else if (ieversion = =) {return 0x02710;//10000 (0x02710), 10001 (0x2711)            } else if (ieversion = =) {return 0x2af8;//11000 (0X2AF8), 11001 (0x2af9        } return 0; }    }

Finally, it is called when the program starts:

Ieversion.browseremulationset ();

Then check the registry to see that it has been modified successfully. Run the program again and find that the problem is resolved.

Above is just one way to solve the problem, not the official authority, improper place please correct me

Took a day to solve a problem (just temporary), think it is very sad, this efficiency if the boss know ...

This is a very many years ago code, even if he is very antique, but there must be something I deserve to learn, this is only the first step, there are many pits to fill, several years down also did accumulate a lot of bugs, at least once was brilliant too ...

Of course, will be revised (it is decided to adjust to the Web version) ....

Looking back at his blog, miserable (zhi) not (Guai) endure (Tai) to see (LAN), the back still have more building blocks

WebBrowser kernel designation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.