我在我的应用程序中创建了一个“帮助”功能,打开一个对话框,如下所示:
左侧的控件是TreeView
。右侧的控件是WebBrowser
。 WebBrowser
填充了一个Word文档,转换为.mhtml
(包含图片的HTML)。
我正在使用您在图像上看到的表格,链接是可点击的,用户将被定向到文档上的位置。有没有办法在左边的TreeView
中显示该表?如果有可能,有人可以给我一个例子,告诉我如何获得想要的结果吗?
修改
<h2 style=3D'mso-list:l9 level2 lfo12'><a name=3D"_Toc353271009"><![if !sup=
portLists]><span
style=3D'mso-fareast-font-family:Calibri;mso-fareast-theme-font:minor-latin;
mso-bidi-font-family:Calibri;mso-bidi-theme-font:minor-latin'><span
style=3D'mso-list:Ignore'>2.2<span style=3D'font:7.0pt "Times New Roman"'>&=
nbsp;
</span></span></span><![endif]>Eerste keer opstarten Liveduiven Client</a><=
/h2>
上面的代码是表格中的链接。
使其更清晰的另一个链接:
style='mso-no-proof:yes'><o:p></o:p></span></p>
<p class=MsoToc1 style='tab-stops:22.0pt right dotted 481.45pt'><span
class=MsoHyperlink><span style='mso-no-proof:yes'><a href="#_Toc353271007">2<span
style='color:windowtext;text-decoration:none;text-underline:none'><span
style='mso-tab-count:1'> </span></span>DE LIVEDUIVEN CLIENT<span
style='color:windowtext;display:none;mso-hide:screen;text-decoration:none;
text-underline:none'><span style='mso-tab-count:1 dotted'>. </span></span>
答案 0 :(得分:1)
我不知道你的html内容的结构,但我写了一个例子(你怎么能这样做):
导航到您的网址
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://en.wikipedia.org/wiki/Microsoft");
}
获取您网页主题的元素
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Get header of subject
foreach (HtmlElement elementintable in webBrowser1.Document.GetElementById("toc").All)
{
if (elementintable.TagName == "A")
{
//insert key and string to each node
treeView1.Nodes.Add(elementintable.GetAttribute("href").Split('#')[1], elementintable.InnerText);
}
}
}
获取选定的节点密钥
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
//navigate to selected anchor
webBrowser1.Document.GetElementById(e.Node.Name).ScrollIntoView(true);
}
<强>结果强>
完整代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Navibate To your url
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("http://en.wikipedia.org/wiki/Microsoft");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Get header of subject
foreach (HtmlElement elementintable in webBrowser1.Document.GetElementById("toc").All)
{
if (elementintable.TagName == "A")
{
//insert key and string to each node
treeView1.Nodes.Add(elementintable.GetAttribute("href").Split('#')[1], elementintable.InnerText);
}
}
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
//navigate to selected anchor
webBrowser1.Document.GetElementById(e.Node.Name).ScrollIntoView(true);
}
}