Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# webbrowser未刷新样式表_C#_Css_Browser_Reloading - Fatal编程技术网

C# webbrowser未刷新样式表

C# webbrowser未刷新样式表,c#,css,browser,reloading,C#,Css,Browser,Reloading,我在下面发布了完整的代码,这样你就可以看到我在做什么了 情况: 我创建了一个指向DomDocument的IHTMLDocument2 currentDoc 我写正确的字符串 我关闭当前文档 程序显示我的html代码,包括CSS的东西100%正确。工作 现在我想更改CSS,而不是2列,我将其设置为3列 (只需将宽度:48%更改为宽度:33%) 并使用新的33%重新运行代码 现在它突然不再应用任何CSS样式了 当我关闭程序,然后再次将CSS更改为33%时,它工作得完美无缺 因此,不知何故,如果不处理

我在下面发布了完整的代码,这样你就可以看到我在做什么了

情况: 我创建了一个指向DomDocument的IHTMLDocument2 currentDoc 我写正确的字符串 我关闭当前文档

程序显示我的html代码,包括CSS的东西100%正确。工作

现在我想更改CSS,而不是2列,我将其设置为3列 (只需将宽度:48%更改为宽度:33%)

并使用新的33%重新运行代码 现在它突然不再应用任何CSS样式了

当我关闭程序,然后再次将CSS更改为33%时,它工作得完美无缺

因此,不知何故,如果不处理完整的webbrowser,我就无法第二次加载CSS。。 或者,第一个CSS位于某个缓存中的某个位置,并且与第二个CSS冲突。。只是在这里骑自行车。。真的需要帮助解决这个问题吗

我在互联网上搜索了很长时间,以至于我需要发布这个,即使这个星球上的其他人已经在某处发布了它,我也没有找到它

    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();
    }
private void doWebBrowserPreview()
{
如果(lMediaFiles.Count==0)
{
返回;
}
Int32指数=0;
对于(iIndex=0;iIndex3)
{
str_sizeMB.插入(str_sizeMB.Length-3,“.”;
}
//获取有关我们媒体文件的信息
MediaInfo MI=新的MediaInfo();
打开(strLinkHTM+lMediaFiles[iIndex].getFileM4V());
字符串str_m4vDuration=//MI.Get(0,0,80);
MI.Get(StreamKind.Video,0,74);
str_m4vDuration=“持续时间:“+str_m4vDuration.Substring(0,8)+”-小时:分钟:秒”;
字符串str_m4vHeightPixel=MI.Get(StreamKind.Video,0,“高度”);/“高度(像素):”+
Int32 i_32m4vHeightPixel;
Int32.TryParse(str_m4vHeightPixel,out i_32m4vHeightPixel);
i_32m4vHeightPixel+=16;//用于quicktime嵌入菜单
str_m4vHeightPixel=i_32m4vHeightPixel.ToString();
字符串str_m4vWidthPixel=MI.Get(StreamKind.Video,0,“宽度”);/“宽度(像素):”+
foreach(s.getTemplates().getMovieHTM().Element(“文件”).Elements(“文件”)中的XElement xmlLine)
{
var query=xmlLine.Attributes(“类型”);
foreach(XAttribute查询结果)
{
如果(result.Value==“htm_头”)
{
foreach(XElement xmlLineDes在xmlLine.subjections()中)
{
if(xmlLineDes.Name==“数据线”)
{
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=“”+“\n”;
foreach(s.getTemplates().getLayoutCSS().Element(“layoutCSS”).Elements(“布局”)中的XElement xmlLine)
{
var query=xmlLine.Attributes(“类型”);
foreach(XAttribute查询结果)
{
如果(result.Value==“layoutMedia”)
{
foreach(xmlLine.Elements(“布局”)中的XElement xmlLineDes)
{
var queryL=xmlLineDes.Attributes(“类型”);
foreach(XAttribute resultL in queryL)
{
如果(resultL.Value==“layoutVideoBox”)
{
foreach(xmlLineDes.subjections()中的XElement xmlLineDesL)
{
if(xmlLineDesL.Name==“数据线”)
{
strLine+=xmlLineDesL.Value+“\n”;
}
}
}
}
}
}
}
}
strLine+=“+”\n”;
strPreview=strPreview.Insert(strPreview.LastIndexOf(“”,StringComparison.Ordinal),strLine);
对于(Int16 i16Loop=0;i16Loop<3;i16Loop++)
{
foreach(s.getTemplates().getMovieHTM().Element(“文件”).Elements(“文件”)中的XElement xmlLine)
{
var query=xmlLine.Attributes(“类型”);
foreach(XAttribute查询结果)
{
如果(result.Value==“htm\u videolist”)
{
foreach(XElement xmlLineDes在xmlLine.subjections()中)
{
if(xmlLineDes.Name==“数据线”)
{
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);