2017-02-18 4 views
0

다음 코드는 CSS를 사용하여 행 색상이 교대로 바뀌는 테이블을 HTML 파일에 작성합니다. 디스크에 기록한 후 예를 들어 html 파일을 직접 볼 때. 파이어 폭스, 크롬, IE 등, 교대 행 색상을 볼 수 있습니다. 그러나 VS2015에서 WebBrowser1 컨트롤로 html 파일을로드 한 후에는 행의 색상이 번갈아 가며 표시되지 않습니다.VS 2015 - WebBrowser 컨트롤이 CSS의 테이블 행 색상을 번갈아 나타내지 않음

다른 게시물을 확인한 결과 WebBrowser가 IE를 랩핑하고 WebBrowser의 문제를 극복하기 위해 타사 오픈 소스 설치와 관련된 해결 방법이 있습니다. 그러나 MS의이 문제에 대한 직접적인 해결책은 무엇입니까? 이것은 VS2015에 번들 된 현재 컨트롤이 CSS에 문제가 있음을 의미하기 때문에 MS 및 VS2015에 대한 미개발 문제처럼 보입니다. 이것에 대한 MS 기반 솔루션은 무엇입니까?

Dim sw As New StreamWriter(filename) 
sw.WriteLine("<!DOCTYPE html><html><body>") 
sw.WriteLine("<style type=" & """" & "text/css" & """" & ">") 
sw.WriteLine("table.gridtable {") 
sw.WriteLine(" font-family: verdana,arial,sans-serif;") 
sw.WriteLine(" font-size:12px;") 
sw.WriteLine(" color: #333333;") 
sw.WriteLine(" border-width: 1px;") 
sw.WriteLine(" border-color: #666666;") 
sw.WriteLine(" border-collapse: collapse;") 
sw.WriteLine("}") 
sw.WriteLine("table.gridtable th {") 
sw.WriteLine(" border-width: 1px;") 
sw.WriteLine(" padding: 8px;") 
sw.WriteLine(" border-style: solid;") 
sw.WriteLine(" border-color: #666666;") 
sw.WriteLine(" background-color: #dedede;") 
sw.WriteLine("}") 
sw.WriteLine("table.gridtable tr {") 
sw.WriteLine("background-color: #ffffff;") 
sw.WriteLine("}") 
sw.WriteLine("table.gridtable tr:nth-child(even) {") 
sw.WriteLine("background-color: #fdf5e6;") 
sw.WriteLine("}") 
sw.WriteLine("table.gridtable td {") 
sw.WriteLine(" border-width: 1px;") 
sw.WriteLine(" padding: 8px;") 
sw.WriteLine(" border-style: solid;") 
sw.WriteLine(" border-color: #666666;") 
sw.WriteLine("}") 
sw.WriteLine("</style>") 

sw.WriteLine("<table class=" & """" & "gridtable" & """" & " Align=center>") 
sw.WriteLine("<tr>") 
sw.Write("<th>" & "Output" & "</th>") 
sw.Write("<th>" & "Output" & "</th>") 
sw.Write("<th>" & "Output" & "</th>") 
sw.Write("<th>" & "Output" & "</th>") 
sw.WriteLine("</tr>") 
sw.WriteLine("<tr>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("</tr>") 
sw.WriteLine("<tr>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("</tr>") 
sw.WriteLine("<tr>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("</tr>") 
sw.WriteLine("<tr>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>") 
sw.WriteLine("</tr>") 
sw.WriteLine("</table>") 
sw.WriteLine("</body></html>") 
sw.dispose 
+0

이 페이지 체크 아웃 http://stackoverflow.com/questions/3822537/wpf-webbrowser-control-what-browser-does-it-use –

+0

및 https://social.msdn.microsoft.com/Forums/ vstudio/ko-ko/6abee729-ac0b-47c5-9603-d1b3050618af/webbrowser-not-applying-css-correctly? forum = wpf –

답변

0

해결 방법 : 다른 사람들을 돕기 위해 Configuring the emulation mode of an Internet Explorer WebBrowser control, by Richard James Moss에 게시 된 C# 솔루션을 VB.NET으로 변환했습니다.

먼저 독립 모듈 (되지 예를 Form1)에 다음의 수입을 추가

Imports Microsoft.Win32 
Imports System.Security 

다음에, 모듈에 다음 클래스를 추가 마지막

Public Class InternetExplorerBrowserEmulation 
    Public Enum BrowserEmulationVersion 
     [Default] = 0 
     Version7 = 7000 
     Version8 = 8000 
     Version8Standards = 8888 
     Version9 = 9000 
     Version9Standards = 9999 
     Version10 = 10000 
     Version10Standards = 10001 
     Version11 = 11000 
     Version11Edge = 11001 
    End Enum 
    Private Const BrowserEmulationKey As String = InternetExplorerRootKey & "\Main\FeatureControl\FEATURE_BROWSER_EMULATION" 
    Public Function GetBrowserEmulationVersion() As BrowserEmulationVersion 
     Dim result As BrowserEmulationVersion 

     result = BrowserEmulationVersion.Default 

     Try 
      Dim key As RegistryKey 

      key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, True) 
      If key IsNot Nothing Then 
       Dim programName As String 
       Dim value As Object 

       programName = Path.GetFileName(Environment.GetCommandLineArgs()(0)) 
       value = key.GetValue(programName, Nothing) 

       If value IsNot Nothing Then 
        result = CType(Convert.ToInt32(value), BrowserEmulationVersion) 
       End If 
      End If 
     Catch e1 As SecurityException 
      ' The user does not have the permissions required to read from the registry key. 
     Catch e2 As UnauthorizedAccessException 
      ' The user does not have the necessary registry rights. 
     End Try 

     Return result 
    End Function 

    Public Function IsBrowserEmulationSet() As Boolean 
     Return GetBrowserEmulationVersion() <> BrowserEmulationVersion.Default 
    End Function 

    Public Function SetBrowserEmulationVersion(ByVal browserEmulationVersion As BrowserEmulationVersion) As Boolean 
     Dim result As Boolean 

     result = False 

     Try 
      Dim key As RegistryKey 

      key = Registry.CurrentUser.OpenSubKey(BrowserEmulationKey, True) 

      If key IsNot Nothing Then 
       Dim programName As String 

       programName = Path.GetFileName(Environment.GetCommandLineArgs()(0)) 

       If browserEmulationVersion <> BrowserEmulationVersion.Default Then 
        ' if it's a valid value, update or create the value 
        key.SetValue(programName, CInt(Fix(browserEmulationVersion)), RegistryValueKind.DWord) 
       Else 
        ' otherwise, remove the existing value 
        key.DeleteValue(programName, False) 
       End If 

       result = True 
      End If 
     Catch e1 As SecurityException 
      ' The user does not have the permissions required to read from the registry key. 
     Catch e2 As UnauthorizedAccessException 
      ' The user does not have the necessary registry rights. 
     End Try 

     Return result 
    End Function 

    Public Function SetBrowserEmulationVersion() As Boolean 
     Dim ieVersion As Integer 
     Dim emulationCode As BrowserEmulationVersion 

     ieVersion = GetInternetExplorerMajorVersion() 

     If ieVersion >= 11 Then 
      emulationCode = BrowserEmulationVersion.Version11 
     Else 
      Select Case ieVersion 
       Case 10 
        emulationCode = BrowserEmulationVersion.Version10 
       Case 9 
        emulationCode = BrowserEmulationVersion.Version9 
       Case 8 
        emulationCode = BrowserEmulationVersion.Version8 
       Case Else 
        emulationCode = BrowserEmulationVersion.Version7 
      End Select 
     End If 

     Return SetBrowserEmulationVersion(emulationCode) 
    End Function 

    Private Const InternetExplorerRootKey As String = "Software\Microsoft\Internet Explorer" 

    Public Function GetInternetExplorerMajorVersion() As Integer 
     Dim result As Integer = Nothing 

     result = 0 

     Try 
      Dim key As RegistryKey 

      key = Registry.LocalMachine.OpenSubKey(InternetExplorerRootKey) 

      If key IsNot Nothing Then 
       Dim value As Object 

       value = If(key.GetValue("svcVersion", Nothing), key.GetValue("Version", Nothing)) 

       If value IsNot Nothing Then 
        Dim version As String 
        Dim separator As Integer 

        version = value.ToString() 
        separator = version.IndexOf("."c) 
        If separator <> -1 Then 
         Integer.TryParse(version.Substring(0, separator), result) 
        End If 
       End If 
      End If 
     Catch e1 As SecurityException 
      ' The user does not have the permissions required to read from the registry key. 
     Catch e2 As UnauthorizedAccessException 
      ' The user does not have the necessary registry rights. 
     End Try 

     Return result 
    End Function 
End Class 

상기를 Form1_Load 절차에서, 다음 코드를 추가하십시오.

프로그램 시작시 IE 에뮬레이션이 수행되므로 전체 CSS 기능은 웹 브라우저 컨트롤에서 볼 수 있습니다.