2011-07-28 1 views
1

아래 코드를 게시하면 내가하는 일을 볼 수 있습니다. webbrowser 스타일 시트가 새로 고쳐지지 않습니다

상황

: 는 나는 내가 currentDoc에게

프로그램을 종료 적절한 문자열 쓰기 나에게 CSS 물건 정확한 100 %를 포함하여 HTML 코드를 보여줍니다 DOMDocument를 에 IHTMLDocument2에의 currentDoc 가리키는를 작성합니다. 작품

지금 나는 CSS를 변경하려면 내가 3 열 (간단히 폭 변경 : 폭 48 % : 33 %)로 설정 대신 2 열로

을 새로운 33의 코드를 다시 실행 % 이제 갑자기 CSS 스타일이 적용되지 않습니다.

내가 프로그램을 닫은 다음 다시 33 %로 CSS를 변경

, 그것은 전체 웹 브라우저를 폐기하지 않고, 어떻게 든, 그래서 완벽한

작동, 나는 CSS에게 2 시간을로드 할 수 없습니다 .. 또는, 첫 번째 CSS가 어딘가에 일부 캐시에 충돌하고 2 CSS를 .. 그냥 여기에 riddling .. 정말이 문제를 해결하는 방법에 대한 도움이 필요합니다

난 인터넷과 stackoverflow 충분히 내가 이것을 게시해야 검색 이 행성에있는 다른 누군가가 이미 어딘가에 게시 했더라도 찾지 못했습니다.

private void doWebBrowserPreview() 
    { 
     if (lMediaFiles.Count == 0) 
     { 
      return; 
     } 

     Int32 iIndex = 0; 
     for (iIndex = 0; iIndex < lMediaFiles.Count; iIndex++) 
     { 
      if (!lMediaFiles[iIndex].isCorrupt()) 
      { 
       break; 
      } 
     } 

     String strPreview = String.Empty; 
     String strLine = String.Empty; 

     // Set example Media 
     String strLinkHTM = lMediaFiles[iIndex].getFilePath(); 
     FileInfo movFile = new FileInfo(strLinkHTM + lMediaFiles[iIndex].getFileMOV()); 
     String str_sizeMB = (movFile.Length/1048576).ToString(); 
     if (str_sizeMB.Length > 3) 
     { 
      str_sizeMB.Insert(str_sizeMB.Length - 3, "."); 
     } 

     //Get info about our media files 
     MediaInfo MI = new MediaInfo(); 
     MI.Open(strLinkHTM + lMediaFiles[iIndex].getFileM4V()); 
     String str_m4vDuration = // MI.Get(0, 0, 80); 
     MI.Get(StreamKind.Video, 0, 74); 
     str_m4vDuration = "Duration: " + str_m4vDuration.Substring(0, 8) + " - Hours:Minutes:Seconds"; 
     String str_m4vHeightPixel = MI.Get(StreamKind.Video, 0, "Height"); // "Height (Pixel): " + 
     Int32 i_32m4vHeightPixel; 
     Int32.TryParse(str_m4vHeightPixel, out i_32m4vHeightPixel); 
     i_32m4vHeightPixel += 16; // for the quicktime embed menu 
     str_m4vHeightPixel = i_32m4vHeightPixel.ToString(); 
     String str_m4vWidthPixel = MI.Get(StreamKind.Video, 0, "Width"); //"Width (Pixel): " + 

     foreach (XElement xmlLine in s.getTemplates().getMovieHTM().Element("files").Elements("file")) 
     { 
      var query = xmlLine.Attributes("type"); 
      foreach (XAttribute result in query) 
      { 
       if (result.Value == "htm_header") 
       { 
        foreach (XElement xmlLineDes in xmlLine.Descendants()) 
        { 
         if (xmlLineDes.Name == "dataline") 
         { 
          strLine = xmlLineDes.Value; 
          strLine = strLine.Replace(@"%date%", lMediaFiles[iIndex].getDay().ToString() + " " + lMediaFiles[iIndex].getMonth(lMediaFiles[iIndex].getMonth()) + " " + lMediaFiles[iIndex].getYear().ToString()); 
          strPreview += strLine + "\n"; 
         } 
        } 
       } 
      } 
     } 

     strLine = "<style type=\"text/css\">" + "\n"; 
     foreach (XElement xmlLine in s.getTemplates().getLayoutCSS().Element("layoutCSS").Elements("layout")) 
     { 
      var query = xmlLine.Attributes("type"); 
      foreach (XAttribute result in query) 
      { 
       if (result.Value == "layoutMedia") 
       { 
        foreach (XElement xmlLineDes in xmlLine.Elements("layout")) 
        { 
         var queryL = xmlLineDes.Attributes("type"); 
         foreach (XAttribute resultL in queryL) 
         { 
          if (resultL.Value == "layoutVideoBox") 
          { 
           foreach (XElement xmlLineDesL in xmlLineDes.Descendants()) 
           { 
            if (xmlLineDesL.Name == "dataline") 
            { 
             strLine += xmlLineDesL.Value + "\n"; 
            } 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
     strLine += "</style>" + "\n"; 
     strPreview = strPreview.Insert(strPreview.LastIndexOf("</head>", StringComparison.Ordinal), strLine); 


     for (Int16 i16Loop = 0; i16Loop < 3; i16Loop++) 
     { 
      foreach (XElement xmlLine in s.getTemplates().getMovieHTM().Element("files").Elements("file")) 
      { 
       var query = xmlLine.Attributes("type"); 
       foreach (XAttribute result in query) 
       { 
        if (result.Value == "htm_videolist") 
        { 
         foreach (XElement xmlLineDes in xmlLine.Descendants()) 
         { 
          if (xmlLineDes.Name == "dataline") 
          { 
           strLine = xmlLineDes.Value; 
           strLine = strLine.Replace(@"%m4vfile%", strLinkHTM + lMediaFiles[iIndex].getFileM4V()); 
           strLine = strLine.Replace(@"%moviefile%", strLinkHTM + lMediaFiles[iIndex].getFileMOV()); 
           strLine = strLine.Replace(@"%height%", str_m4vHeightPixel); 
           strLine = strLine.Replace(@"%width%", str_m4vWidthPixel); 
           strLine = strLine.Replace(@"%duration%", str_m4vDuration); 
           strLine = strLine.Replace(@"%sizeMB%", str_sizeMB); 
           strLine = strLine.Replace(@"%date%", lMediaFiles[iIndex].getDay().ToString() + " " + lMediaFiles[iIndex].getMonth(lMediaFiles[iIndex].getMonth()) + " " + lMediaFiles[iIndex].getYear().ToString()); 
           strPreview += strLine + "\n"; 
          } 
         } 
        } 
       } 
      } 
     } 

     foreach (XElement xmlLine in s.getTemplates().getMovieHTM().Element("files").Elements("file")) 
     { 
      var query = xmlLine.Attributes("type"); 
      foreach (XAttribute result in query) 
      { 
       if (result.Value == "htm_footer") 
       { 
        foreach (XElement xmlLineDes in xmlLine.Descendants()) 
        { 
         if (xmlLineDes.Name == "dataline") 
         { 
          strPreview += xmlLineDes.Value + "\n"; 
         } 
        } 
       } 
      } 
     } 
     webBrowserPreview.Navigate("about:blank"); 
     webBrowserPreview.Document.OpenNew(false); 
     mshtml.IHTMLDocument2 currentDoc = (mshtml.IHTMLDocument2)webBrowserPreview.Document.DomDocument; 
     currentDoc.clear(); 
     currentDoc.write(strPreview); 
     currentDoc.close(); 

     /* 
     try 
     { 
      if (webBrowserPreview.Document != null) 
      { 
       IHTMLDocument2 currentDocument = (IHTMLDocument2)webBrowserPreview.Document.DomDocument; 
       int length = currentDocument.styleSheets.length; 

       IHTMLStyleSheet styleSheet = currentDocument.createStyleSheet(@"", 0); 
       //length = currentDocument.styleSheets.length; 
       //styleSheet.addRule("body", "background-color:blue"); 
       strLine = String.Empty; 
       foreach (XElement xmlLine in s.getTemplates().getLayoutCSS().Element("layoutCSS").Elements("layout")) 
       { 
        var query = xmlLine.Attributes("type"); 
        foreach (XAttribute result in query) 
        { 
         if (result.Value == "layoutMedia") 
         { 
          foreach (XElement xmlLineDes in xmlLine.Elements("layout")) 
          { 
           var queryL = xmlLineDes.Attributes("type"); 
           foreach (XAttribute resultL in queryL) 
           { 
            if (resultL.Value == "layoutVideoBox") 
            { 
             foreach (XElement xmlLineDesL in xmlLineDes.Descendants()) 
             { 
              if (xmlLineDesL.Name == "dataline") 
              { 
               strLine += xmlLineDesL.Value; 
              } 
             } 
            } 
           } 
          } 
         } 
        } 
       } 
       //TextReader reader = new StreamReader(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "basic.css")); 
       //string style = reader.ReadToEnd(); 
       styleSheet.cssText = strLine; 
      } 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     }*/ 

     webBrowserPreview.Refresh(); 
    } 
+0

가 그래서 그냥 스타일 시트의 손상을 일으키는 더 후 같은 파일을 "이동"이라고 찾는 많은 시간을 잃었 때문에이 정보가 다른 사람을 도울 수

희망 CSS 캐싱? 열심히 했니? (CTRL + F5) – abney317

+0

예. 나는 또한 많은 다른 변종을 시도했다. 디스크에 파일 저장 및 탐색 사용 포함.이유는 무엇입니까? "div # video_box"라는 스타일 시트는 세션 중에 변경할 수 없습니다. 웹 브라우저를 자신의 폼에두고 C#이 자동으로 처리해야하는이 양식을 열거 나 닫을 때도 스타일 시트를 변경할 수 없습니다. CSS와 HTML 둘 다에서 이름을 변경하면 변경된 데이터가 올바르게로드되지만 (한번!) 변경 될 때마다 새로운 이름을 사용해야합니다. 열거자를 사용하여 우회 솔루션을 제안 할 수도 있지만 이것이 좋은 해결책은 아닙니다. – Vince

+0

http://www.eggheadcafe.com/software/aspnet/30119924/dynamic-stylesheet-problem.aspx이 문제는 유사한 문제로 생각됩니다. C# webbrowser 구현에 이상한 점이있는 것 같습니다. – Vince

답변

0

는 이제 성공적으로 같은 버그가 내 프로젝트에 버클륨 날카로운 방법을 구현! 해결책을 찾았습니다!

첫 번째 시도가 작동하지 않음 : 난 영구 양식 (기본 양식)이 있고 그 안에 중첩 된 WebBrowser가 있습니다. CSS로 html을 변경 한 후에이 새로운 html로 이동하라고 명령했습니다.

이 중 하나가 작동하지 않았다 : 그럼 나는 자신의 양식에 웹 브라우저를 넣어 보았습니다. 어느 쪽 간단하게 열거 나 닫을 때마다 시간 새로 고침이 필요합니다. 가비지 컬렉터가 모든 것을 정리하는지 확인합니다.

그런 다음 Berkelium을 시도하고이를 내 필요에 맞게 다시 작성했습니다. 웹 브라우저에서 2 번 시도와 동일한 논리를 사용합니다. 행운도 없습니다.

그래서 파이어 폭스 자체를 열고 실제 브라우저로이 동작을 에뮬레이트 할 수 있는지 확인하려고했습니다. 과연! 파이어 폭스를 열고 강제로 파일을 엽니 다. (단순히 새 파일을 열면 파이어 폭스가 실제로 탐색하지 않지만 이미 열려 있고 단순히 새로 고칩니다.) 빠른 열기로 인해 페이지! 1 개의 firefox 세션에서 같은 파일을 두 번 열어 보도록 강요하는 작은 스크립트가 동일한 효과를 나타냅니다 : 모든 CSS가 손상되었습니다!

그래서, 어떤 이유로, 같은 파일을 두 번 탐색해서는 안되며, 무엇이든 닫는 대신 강제로 새로 고침하십시오! 아니 "이동"나는 그것이 한 번