如何禁用webbrowser控件脚本调试
展开全部
在 form1 类的“initializecomponent”方法的末尾,添加以下代码以处理“form1_load”、“form1_closed”和“axwebbrowser1_navigatecomplete2”事件:
this.axwebbrowser1.navigatecomplete2 += new axshdocvw.dwebbrowserevents2_navigatecomplete2eventhandler(this.axwebbrowser1_navigatecomplete2);
this.load += new system.eventhandler(this.form1_load);
this.closed += new system.eventhandler(this.form1_closed);
8. 将下面的代码
private void button1_click(object sender, system.eventargs e)
{
}
替换为:
private void button1_click(object sender, system.eventargs e)
{
string strfilename;
//find the office document.
openfiledialog1.filename = "";
openfiledialog1.showdialog();
strfilename = openfiledialog1.filename;
//if the user does not cancel, open the document.
if(strfilename.length != 0)
{
object refmissing = system.reflection.missing.value;
odocument = null;
axwebbrowser1.navigate(strfilename, ref refmissing , ref refmissing , ref refmissing , ref refmissing);
}
}
public void form1_load(object sender, system.eventargs e)
{
button1.text = "browse";
openfiledialog1.filter = "office documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt" ;
openfiledialog1.filterindex = 1;
}
public void form1_closed(object sender, system.eventargs e)
{
odocument = null;
}
public void axwebbrowser1_navigatecomplete2(object sender, axshdocvw.dwebbrowserevents2_navigatecomplete2event e)
{
//note: you can use the reference to the document object to
// automate the document server.
object o = e.pdisp;
odocument = o.gettype().invokemember("document",bindingflags.getproperty,null,o,null);
object oapplication = o.gettype().invokemember("application",bindingflags.getproperty,null,odocument,null);
object oname = o.gettype().invokemember("name",bindingflags.getproperty ,null,oapplication,null);
messagebox.show("file opened by: " + oname.tostring() );
}
注意:您必须在 visual studio 2005 中更改此代码。默认情况下,当您创建 windows 窗体项目时,visual c# 向该项目添加一个窗体。该窗体被命名为 form1。表示该窗体的两个文件被命名为 form1.cs 和 form1.designer.cs。您在 form1.cs 中编写代码。windows 窗体设计器在 form1.designer.cs 文件中编写代码,这些代码实现通过从工具箱拖放控件所执行的所有操作。
this.axwebbrowser1.navigatecomplete2 += new axshdocvw.dwebbrowserevents2_navigatecomplete2eventhandler(this.axwebbrowser1_navigatecomplete2);
this.load += new system.eventhandler(this.form1_load);
this.closed += new system.eventhandler(this.form1_closed);
8. 将下面的代码
private void button1_click(object sender, system.eventargs e)
{
}
替换为:
private void button1_click(object sender, system.eventargs e)
{
string strfilename;
//find the office document.
openfiledialog1.filename = "";
openfiledialog1.showdialog();
strfilename = openfiledialog1.filename;
//if the user does not cancel, open the document.
if(strfilename.length != 0)
{
object refmissing = system.reflection.missing.value;
odocument = null;
axwebbrowser1.navigate(strfilename, ref refmissing , ref refmissing , ref refmissing , ref refmissing);
}
}
public void form1_load(object sender, system.eventargs e)
{
button1.text = "browse";
openfiledialog1.filter = "office documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt" ;
openfiledialog1.filterindex = 1;
}
public void form1_closed(object sender, system.eventargs e)
{
odocument = null;
}
public void axwebbrowser1_navigatecomplete2(object sender, axshdocvw.dwebbrowserevents2_navigatecomplete2event e)
{
//note: you can use the reference to the document object to
// automate the document server.
object o = e.pdisp;
odocument = o.gettype().invokemember("document",bindingflags.getproperty,null,o,null);
object oapplication = o.gettype().invokemember("application",bindingflags.getproperty,null,odocument,null);
object oname = o.gettype().invokemember("name",bindingflags.getproperty ,null,oapplication,null);
messagebox.show("file opened by: " + oname.tostring() );
}
注意:您必须在 visual studio 2005 中更改此代码。默认情况下,当您创建 windows 窗体项目时,visual c# 向该项目添加一个窗体。该窗体被命名为 form1。表示该窗体的两个文件被命名为 form1.cs 和 form1.designer.cs。您在 form1.cs 中编写代码。windows 窗体设计器在 form1.designer.cs 文件中编写代码,这些代码实现通过从工具箱拖放控件所执行的所有操作。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询