출처 : http://okgood0412.tistory.com/entry/C-WebBrowser-version-%EB%B3%80%EA%B2%BD










Visual Studio C#에서 기본 제공하는 WebBrowser 컴포넌트는 구 버전인 Internet Explorer 7 엔진을 사용 하므로, 차세대 웹 기술인 HTML5 또는 Google map v3 최신 버전 등을 지원하지 못하는 문제가 있다. 


구글링으로 알아본 바로, 해결 방법으로는 3 party component 를 사용는 방법과 프로그램에 Registry 를 조작하는 코드를 심어 놓고 프로그램 구동시 설치된 IE버전과 같은 버전으로 셋팅하는 방법등이 있다.


두번째, Registry 조작(등록) 방법!

  - 현재 PC에 Install 된 IE 버전을 사용하도록 Registry 등록.


* Visual Studio 2015 버전 사용.

* 아래 링크를 참조 하여 테스트 하였습니다. 

1. http://stackoverflow.com/questions/23356194/cannot-force-webbrowser-control-to-render-using-current-version-of-ie


2. http://stackoverflow.com/questions/17922308/use-latest-version-of-ie-in-webbrowser-control



1. Winform Project 생성




2. Program.cs 파일에 소스추가.

  


namespace WebBrowserIEVersionTest

{

    static class Program

    {

        static Mutex mutex = new System.Threading.Mutex(false, "jMutex");


        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        [STAThread]

        static void Main()

        {

            if(!mutex.WaitOne(TimeSpan.FromSeconds(2), false))

            {

                //another application instance is running

                return;

            }


            try

            {

                Application.EnableVisualStyles();

                Application.SetCompatibleTextRenderingDefault(false);


                var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe";

                int browserver = 7;

                int ie_emulation = 11999;


                using (WebBrowser wb = new WebBrowser())

                {

                    browserver = wb.Version.Major;



                    if (browserver >= 11)

                        ie_emulation = 11001;

                    else if (browserver == 10)

                        ie_emulation = 10001;

                    else if (browserver == 9)

                        ie_emulation = 9999;

                    else if (browserver == 8)

                        ie_emulation = 8888;

                    else

                        ie_emulation = 7000;

                }


                try

                {

                    //string tmp = Properties.Settings.Default.Properties.

                    SetIEVersioneKeyforWebBrowserControl(targetApplication, ie_emulation);

                    Application.Run(new Form1());


                }

                catch (Exception ex1)

                {


                }


            }

            catch (Exception ex2)

            {


                

            } finally

            {

                mutex.ReleaseMutex();

            }            

        }


        private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval)

        {

            RegistryKey Regkey = null;

            try

            {

                Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);


                //If the path is not correct or 

                //If user't have priviledges to access registry 

                if (Regkey == null)

                {

                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found");

                    return;

                }


                string FindAppkey = Convert.ToString(Regkey.GetValue(appName));


                //Check if key is already present 

                if (FindAppkey == ieval.ToString())

                {

                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION already set to " + ieval);

                    Regkey.Close();

                    return;

                }


                //If key is not present or different from desired, add/modify the key , key value 

                Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord);


                //check for the key after adding 

                FindAppkey = Convert.ToString(Regkey.GetValue(appName));


                if (FindAppkey == ieval.ToString())

                {

                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart");

                }

                else

                {

                    MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; current value is  " + ieval);

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message);

            }

            finally

            {

                //Close the Registry 

                if (Regkey != null)

                    Regkey.Close();

            }

        }

    }

}


3. 실행결과.

  - 처음 실행시, 변경 됐음을 알림.


  - 동일한 프로그램 재 실행시 이미 변경되었다고 알림.


  - 기존 Default 버전 WebBrowser component 에서 발생했던 Script error가 이 방법을 통해 나타나지 않는것을 확인함!! 



Posted by 요지
,