0

I am using VS2019 with C# .Net 4.7.2.

I have the below code that is used to create a textbox in WebBrowser control by using the following code: -

string HTMLCode = "<html>" + Environment.NewLine +
                  "    <head><style>" + Environment.NewLine +
                  "        input[type=text]::-ms-clear {  display: none; width : 0; height: 0; }" + Environment.NewLine +
                  "    </style></head>" + Environment.NewLine +
                  "<body style=\"margin:0px\" >" + Environment.NewLine +
                  "        <input type='text' id='userName' style=\"border-radius: 5px;font-family: 'Century Gothic';font-weight: bold;font-size: 15px;\" />" + Environment.NewLine +
                  "</body >" + Environment.NewLine +
                  "</html >";

webBrowser1.DocumentText = HTMLCode;

Which Looks like this: -

enter image description here

The Below line is added to remove Clear (X) button from input box which is shown in IE9 or some other versions browser the WebBrowser is using: -

input[type=text]::-ms-clear {  display: none; width : 0; height: 0; }

Below code is used to ensure that it works as close as it can to IE9 (picked from a post in stack overflow, don't have the link of it) and is called at form load event. SetBrowserFeatureControl();

#region SetBrowserFeatureControl
    public static void SetBrowserFeatureControl()
    {
        // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

        // FeatureControl settings are per-process
        var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);

        // make the control is not running inside Visual Studio Designer
        if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0)
            return;

        SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode()); // Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
        SetBrowserFeatureControlKey("FEATURE_AJAX_CONNECTIONEVENTS", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_ENABLE_CLIPCHILDREN_OPTIMIZATION", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_MANAGE_SCRIPT_CIRCULAR_REFS", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_DOMSTORAGE ", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_GPU_RENDERING ", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI  ", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_DISABLE_LEGACY_COMPRESSION", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_LOCALMACHINE_LOCKDOWN", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_OBJECT", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_BLOCK_LMZ_SCRIPT", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_DISABLE_NAVIGATION_SOUNDS", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_SCRIPTURL_MITIGATION", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_SPELLCHECKING", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_STATUS_BAR_THROTTLING", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_TABBED_BROWSING", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_VALIDATE_NAVIGATE_URL", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_WEBOC_DOCUMENT_ZOOM", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_WEBOC_POPUPMANAGEMENT", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_WEBOC_MOVESIZECHILD", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_ADDON_MANAGEMENT", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_WEBSOCKET", fileName, 1);
        SetBrowserFeatureControlKey("FEATURE_WINDOW_RESTRICTIONS ", fileName, 0);
        SetBrowserFeatureControlKey("FEATURE_XMLHTTP", fileName, 1);
    }

    private static void SetBrowserFeatureControlKey(string feature, string appName, uint value)
    {
        using (var key = Registry.CurrentUser.CreateSubKey(
            String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature),
            RegistryKeyPermissionCheck.ReadWriteSubTree))
        {
            key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord);
        }
    }

    private static UInt32 GetBrowserEmulationMode()
    {
        int browserVersion = 7;
        using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
            RegistryKeyPermissionCheck.ReadSubTree,
            System.Security.AccessControl.RegistryRights.QueryValues))
        {
            var version = ieKey.GetValue("svcVersion");
            if (null == version)
            {
                version = ieKey.GetValue("Version");
                if (null == version)
                    throw new ApplicationException("Microsoft Internet Explorer is required!");
            }
            int.TryParse(version.ToString().Split('.')[0], out browserVersion);
        }

        UInt32 mode = 11000; // Internet Explorer 11. Webpages containing standards-based !DOCTYPE directives are displayed in IE11 Standards mode. Default value for Internet Explorer 11.
        switch (browserVersion)
        {
            case 7:
                mode = 7000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
                break;
            case 8:
                mode = 8000; // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
                break;
            case 9:
                mode = 9000; // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                break;
            case 10:
                mode = 10000; // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 mode. Default value for Internet Explorer 10.
                break;
            default:
                // use IE11 mode by default
                break;
        }

        return mode;
    }
    #endregion

Problem

Whenever I click on the input box, the input box shrinks by 1px or 2px and goes back to normal on mouse up.

Things I have checked

  1. There is no other event called for webbrowser other than the one's I mentioned above.
  2. Running the same HTML code in browser like (IE9, Chrome) doesn't show this bug.

To actually see it you have to run the above code.

halfer
  • 19,824
  • 17
  • 99
  • 186
Agent_Spock
  • 1,107
  • 2
  • 16
  • 44

0 Answers0