System.Windows.Form.HtmlDocument 中的 "htmlstring" 怎么写,没有构造函数,有没有其他方法初始化它?

How to write "htmlstring" in System.Windows.Form.HtmlDocument ,it doesn't have constructor, Is there another way to initialize it?

//此代码未使用 HTML Agility Pack HtmlDocument .

1) 我在字符串

中有 html 个元素

2) 我想把它写在 System.Windows.Form.HtmlDocument 但它不允许,因为它的构造函数是不允许的

System.Windows.Form.HtmlDocument document=new HtmlDocument()//not allowed
document.write(htmlstring);

foreach (HtmlElement element in document.All)
{                        
    string size = element.GetAttribute("font-size");
    string font = element.GetAttribute("color");
    string fontfamily = element.GetAttribute("font-family");
}

问题 1:How 在代码的第 1 行定义构造函数。

问题2:I 没怎么研究,我发现htmlAgilitypack 与定义构造函数有关,但它很混乱,因为htmlAgilitypack 还包含HtmlDocument 的定义。如何使用 htmlAgilityPack 获取属性?

完全可以使用HtmlAgilityPack解决,将System.Windows.Form.HtmlDocument的代码替换为HtmlAgilityPack.HtmlDocument文档

   HtmlAgilityPack.HtmlDocument document  =new  HtmlAgilityPack.HtmlDocument();
                document.LoadHtml(HTML);
                IEnumerable<HtmlNode> links = document.DocumentNode.Descendants("span");
                foreach (var element in links)
                {
                   string style = element.Attributes["style"].Value;
                   string[] styles=style.Split(';');
                   richTextBox1.Text += "\n" + styles[0].Replace("font-family:", "");
                   richTextBox1.Text += "\n" + styles[1].Replace("font-size:", "");
                   richTextBox1.Text += "\n" + styles[2].Replace("color:", "");
                }