解决方案 »
- 下面这段导出为excel的思路谁能解释一下吗
- DevExpress.XtraReports.UI.XRCheckBox控件
- 高人请进
- 获取GridView动态模板中TextBox控件的ID
- 未找到产品visual studio.net Enterprise Architect 2003-chs的有效源是什么原因 ?
- 当两个连接的Socket的一端断开后。另一端怎样来获得这个消息???
- 请教一个用C#在winform下做GDI+画图的问题
- 求Office的AddIn 开发流程相关资源
- 急急急,有这样一个string,在这个string中是用‘,’逗号分开的许多小string阿,怎么分别读取他们保存到一个string去?
- 请问在c#中,接口和抽象类是什么意思,通常是派什么用处的
- C# 要怎么做到WCF服务地址变更后只配置一下webconfig文件
- 在.net做的网页中嵌入swf视频,为什么视频只能播放一部分????高手进。。急求
下面代码中htmlEditor_DocumentCompleted中的设置就不起作用,但是点击下按钮button1_Click,就ok了。
private void button1_Click(object sender, EventArgs e)
{
bool res = doc.execCommand("FontName", true, "Arial");
res = doc.execCommand("FontSize", true, 12);
} private void htmlEditor_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
htmlEditor.Focus();
doc = htmlEditor.Document.DomDocument as IHTMLDocument2;
doc.designMode = "On";
bool res = doc.execCommand("FontName", true, "Arial");
res = doc.execCommand("FontSize", true, 12); }
htmlEditor_DocumentCompleted
是不起作用,我在加载的是就设置了
下面的是可以的:private void htmlEditor_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
htmlEditor.Focus();
doc = htmlEditor.Document.DomDocument as IHTMLDocument2;
doc.designMode = "On";
bToChangeFond = true; //这里doc.readyState是loading.设置定时器等状态为complete再执行execCommand
timer1.Start();
} private void timer1_Tick(object sender, EventArgs e)
{
if (bToChangeFond)
{
if (doc.readyState == "complete")
{
bool res = doc.execCommand("FontName", true, "Arial");
res = doc.execCommand("FontSize", true, 12);
bToChangeFond = false;
timer1.Stop();
}
} }
你可以看一下IHTMLDocument2的onreadystatechange属性(事件?)。我对这方面也不太熟。
{
htmlEditor.DocumentText = "<html><body></body></html>";
doc = htmlEditor.Document.DomDocument as IHTMLDocument2;
doc.designMode = "On";
bToChangeFond = true;
//timer1.Start();
DHTMLEventHandler myHandler = new DHTMLEventHandler(doc);
myHandler.Handler += new DHTMLEvent(this.SetFont);
doc.onreadystatechange = myHandler;
} private void SetFont(IHTMLEventObj e)
{
if (bToChangeFond)
{
if (doc.readyState == "complete")
{
bool res = doc.execCommand("FontName", true, "Arial");
res = doc.execCommand("FontSize", true, 12);
bToChangeFond = false;
}
}
} public delegate void DHTMLEvent(IHTMLEventObj obj); [ComVisible(true)]
public class DHTMLEventHandler
{
public DHTMLEvent Handler; private IHTMLDocument2 Document; public DHTMLEventHandler(IHTMLDocument2 doc)
{
Document = doc;
} [DispId(0)]
public void Call()
{
Handler(Document.parentWindow.@event);
}
}
onreadystatechange部分代码参考了讨论:
http://stackoverflow.com/questions/7222281/assigning-onmouseover-event-to-my-htmldocument-is-not-working
if (doc.readyState == "complete")
跑完了状态没有complete 只有interactive,loading 这2个状态
loading, interactive, complete。难道版本不同,你价格button,等段时间,进去看看状态是什么?实在不行也来个timer吧。