1。首先引用 Microsoft.mshtml;
2. 写代码
private void BtnInsertMedia_Click(object sender, EventArgs e)
{
InWord frm = new InWord("请填入视频地址(后缀必须是.swf):");
frm.ShowDialog();
if (frm.Value != null && frm.Value != "")
{
IHTMLDocument2 doc = (IHTMLDocument2)this.webBrowser1.Document.DomDocument;
IHTMLTxtRange range = doc.selection.createRange() as IHTMLTxtRange;
range.pasteHTML(range.text + @"<br \><embed wmode=""transparent"" src=""" + frm.Value + @""" quality=""high"" width=""480"" height=""400"" align=""middle"" allow script Access=""always"" allowfullscreen=""true"" type=""application/x-shockwave-flash""></embed><br \>");
}
}
Popularity: 17% [?]
C# WebBrower1控件可编辑模式保存时会提示“该文档已被修改,是否保存修改结果”
在百度查了不少方法,张筱祥发现一个比较实用而且非常简单的方法,代码如下:
在WebBrower1的Navigating 事件中加以下代码就没有提示了。
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
webBrowser1.Document.Write("<script>functionshowModalDialog{return;}</script>");
}
ok,问题完美解决,不再弹窗那个让人讨厌的对话框了。
Popularity: 20% [?]
在网上找了点资料,自己测试了一下,发现C#操作webBrowser也不是很难。这里写几句简单的记录。
首先在from_load事件中添加以下代码:
webBrowser1.DocumentText = string.Empty;
webBrowser1.Document.ExecCommand("EditMode", false, null);
webBrowser1.Document.ExecCommand("LiveResize", false, null);
webBrowser1.DocumentText = @"现在";
然后webBrowser1里面内容就可以编辑了
其中如果需要得到webBrowser1中的内容可以使用:
webBrowser1.Document.Body.InnerText 和 webBrowser1.Document.Body.InnerHtml
从字面意思上可以看出是分别获取webBrowser1的文本形式内容和html形式内容。
Popularity: 30% [?]
最新评论