C# 在webbrowser中隐藏HTML标记
我想在我的web浏览器中隐藏一个HTML标记。我遇到的问题是我不能使用javascript。 我想出了这段代码:C# 在webbrowser中隐藏HTML标记,c#,html,browser,C#,Html,Browser,我想在我的web浏览器中隐藏一个HTML标记。我遇到的问题是我不能使用javascript。 我想出了这段代码: public void HideHTMLTag(string ControlID) { HtmlDocument doc = webBrowser1.Document; HtmlElement HTMLControl = doc.GetElementById(ControlID); HTMLControl.Style =
public void HideHTMLTag(string ControlID)
{
HtmlDocument doc = webBrowser1.Document;
HtmlElement HTMLControl = doc.GetElementById(ControlID);
HTMLControl.Style = "'display: none;'";
webBrowser1.Refresh();
}
我将此称为按钮事件。感谢您的帮助。请尝试documentCompleted事件中的代码。。 网址:-
这是Asp.Net应用程序中使用的代码吗?@AkshayJoy:不是,它是在C#winform中。那么你是在winform中显示HTML吗?更多细节会有所帮助。我还假设您的代码块不工作?它现在做什么?@canhazbits:exatly。我有一个HTML页面,它显示在一个webbrowser中。我想通过使用这个函数隐藏它的一些特定标记。我的意思是,我希望一些标记在某些时候不会显示。
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlDocument doc = webBrowser1.Document;
HtmlElement HTMLControl = doc.GetElementById("question-header");
//HTMLControl.Style = "'display: none;'";
if (HTMLControl != null)
{
HTMLControl.Style = "display: none";
}
}