1

I have created a program in .NET to edit HTML code and view it in realtime, and it work pretty good, but there's a problem: since i used the WebBrowser control it doesn't work with new CSS, for example, if i try border-radius it doesen't work.

I already searched, and i found a way to solve it by editing a key in the regedit, but in this way it work only in my computer, and i need this program to run even on other computers where i don't have privilege to run the regedit.

I thougth about changing control, and i tried the webkit control, and the CSS3 seems to work, but there's a new problem.

I show the page by changing the HTML in real time on the richtextbox textchanged event, so the page isn't really loaded, and the external resource as images and other things doesen't work, in the WebBrowser i fixed the problem by searching all the img tags and changing their attribute, for example i changed "image.png" to "file:///C:\pathoftheHTMLfile\image.png".

That worked good in WebBrowser, but it doesn't work on WebKit... I really don't know what should i do...

I'm gonna trying Gecko Browser soon, but i would like to know if someone have some idea on:

  • Is there some way to use CSS3 in WebBrowser without editing the system registry?
  • Why changing the images does work in WebBrowser but not in Webkit Browser?

Thanks for the help i'm sure you will give me ^_^

UPDATE: I discovered that the change of the image happen correctly in the WebKitBrowser, the problem is that it seems to be able to load only image from internet, not local image, and it seems to be a known problem of the webkit control Opening local files in Webkit .NET

But noone answered to that question in a good way...

UPDATE 2: I tryed doing as Noseratio said in the comments (my code is this)

Private Sub SetBrowserEmulationMode()
        Dim appName As String = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName)
        Using key = Registry.CurrentUser.CreateSubKey("Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree)
            key.SetValue(appName, getBrowserEmulationMode, RegistryValueKind.DWord)
        End Using
    End Sub
    Private Function getBrowserEmulationMode() As UInt32
        Dim browserVersion As Integer = 7
        Using ieKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Internet Explorer", RegistryKeyPermissionCheck.ReadSubTree, System.Security.AccessControl.RegistryRights.QueryValues)
            Dim version = ieKey.GetValue("svcVersion")
            If version Is Nothing Then
                version = ieKey.GetValue("Version")
                If version Is Nothing Then
                    Throw New ApplicationException("Microsoft Internet Explorer is required!")
                End If
            End If
            Integer.TryParse(version.ToString().Split("."c)(0), browserVersion)
        End Using

        Dim mode As UInt32 = 10000
        Select Case browserVersion
            Case 7
                mode = 7000
                Exit Select
            Case 8
                mode = 8000
                Exit Select
            Case 9
                mode = 9000
                Exit Select
        End Select

        Return mode
    End Function

But... even if the key is correctly created, nothing change. I'm trying it with a simple page like:

<html>
<head>
  <style>
  div{border:1px solid black; height:200px;border-radius:10px;}
  </style>
</head>
<body>
  <div>

  </div>
</body>
</html>

But the border is not rounded, even if while i save it and open with IE it's correctly rounded

UPDATE 3: It already worked at update2, i'm a stupid XD

Community
  • 1
  • 1
Celeste Capece
  • 1,306
  • 2
  • 11
  • 20
  • 1
    You don't need admin right to do that. Use `HKCU` hive: http://stackoverflow.com/a/18333982/1768303 – noseratio Apr 25 '15 at 23:27
  • I tried that, and the key is created, but the webbrowser still doesen't work... u can read more details about what i did in the answer, i updated it – Celeste Capece Apr 26 '15 at 00:47
  • my fault, it already worked XD – Celeste Capece Apr 26 '15 at 00:55
  • Try adding ` ` to the beginning of your HTML document, see if it makes any difference. Also try `alert("compatMode: " + document.compatMode + ", documentMode: " + document.documentModeMode)`. What do you see? – noseratio Apr 26 '15 at 01:05
  • Ah, so it worked - good. – noseratio Apr 26 '15 at 01:06
  • possible duplicate of [C# webbrowser Ajax call](http://stackoverflow.com/questions/18333459/c-sharp-webbrowser-ajax-call) – noseratio Apr 27 '15 at 01:38
  • There's something that is not working... i'm gonna put details in the answer soon, sorry if i keep bothering you :S – Celeste Capece Apr 27 '15 at 17:04
  • Well, i don't know why, but it bug if there's an external CSS tag, and since when i put the HTML in the Webbrowser i merge the external files with the HTML putting them in the – Celeste Capece Apr 27 '15 at 17:11
  • anyway that script helped me a lot to notice what was the problem, thanks ^_^ – Celeste Capece Apr 27 '15 at 17:12
  • ok, that finally work, anyway the solution to my problem is the same as this http://stackoverflow.com/questions/18333459/c-sharp-webbrowser-ajax-call but my question is a bit different... should i delete since the answer is the same? – Celeste Capece Apr 27 '15 at 17:38

0 Answers0