代码改变世界

webBrowser控件

2011-06-23 21:51  通心菜  阅读(484)  评论(0编辑  收藏  举报

1 对有ID的文本框赋值

  webBrowser1.Document.GetElementById("emailValue").InnerText = "ganhui21312312@sina.com";

2 设置单选(推荐使用点击事件而不是直接修改属性)

  webBrowser1.Document.GetElementById("controlID").InvokeMember("click");

3 将图片加载到picbox

HTMLDocument html = (HTMLDocument)this.webBrowser1.Document.DomDocument;
IHTMLControlElement img
= (IHTMLControlElement)webBrowser1.Document.Images["regValImg"].DomElement;

IHTMLControlRange range
= (IHTMLControlRange)((HTMLBody)html.body).createControlRange();
range.add(img);
range.execCommand(
"Copy", false, null);
img
= null;
range
= null;
html
= null;
if (Clipboard.ContainsImage())
{
this.pictureBox1.Image = null;
this.pictureBox1.Image = Clipboard.GetImage();

}
Clipboard.Clear();

4 提交表单

HtmlElement form = webBrowser1.Document.GetElementById("submit");
           form.InvokeMember("click");