user3228884
user3228884

Reputation: 131

Display WebPage in C#

I want to display The webpage: http://vhg.cmp.uea.ac.uk/tech/jas/vhg2018/WebGLAv.html in Windows Form of my C# project.

Screenshot of webpage

I use WebBrowser tool in it and write this code to show this webpage in the Form:

webBrowser1.Navigate("http://vhg.cmp.uea.ac.uk/tech/jas/vhg2018/WebGLAv.html");

but it doesn't show the full webpage!

This shows like this

What should I've done?

Upvotes: 1

Views: 1854

Answers (2)

moath naji
moath naji

Reputation: 661

you can use google SDK to browse or using showing html content referee this link

Upvotes: 0

Mojtaba Tajik
Mojtaba Tajik

Reputation: 1733

By default Windows Forms applications use IE wrapper and not guarantee to use latest IE version. Read this article to know what happen behind IE wrappers and what Windows emulation key do.

This code from one of my old project let to change the default emulation version of IE for your executable process programmatically :

private static readonly string BrowserEmulationRegistryKeyPath =
            @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION";

        /// <summary>
        /// Add the process name to internet explorer emulation key
>       /// i do this because the default IE wrapper dose not support the latest JS features
>       /// Add process to emulation key and set a DWord value (11001) for it means we want use IE.11 as WebBrowser component
        /// </summary>
        public bool EmulateInternetExplorer()
        {
            using (
                var browserEmulationKey = Registry.CurrentUser.OpenSubKey(BrowserEmulationRegistryKeyPath,
                    true))
            {
                if (browserEmulationKey == null)
                    Registry.CurrentUser.CreateSubKey(BrowserEmulationRegistryKeyPath);


                string processName = $"{Process.GetCurrentProcess().ProcessName}.exe";

                // Means emulation already added and we are ready to start
                if (browserEmulationKey?.GetValue(processName) != null)
                    return true;

                // Emulation key not exists and we must add it ( We return false because application restart to take effect of changes )
                if (browserEmulationKey != null)
                {
                    browserEmulationKey.SetValue(processName, 11001, RegistryValueKind.DWord);
                    browserEmulationKey.Flush();
                }
                return false;
            }
        }

If your website dose not show properly in latest Internet Explorer (not compatible) you should use other web browser wrappers like cefSharp that embed Chromium in your .Net app.

Upvotes: 2

Related Questions