webBrowser 设置文本框
2011-04-12 18:58 通心菜 阅读(626) 评论(0) 编辑 收藏 举报private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://www.baidu.com");
this.webBrowser1.ScriptErrorsSuppressed = true;
//禁用右键菜单
this.webBrowser1.IsWebBrowserContextMenuEnabled = false;
//禁用键盘快捷键
this.webBrowser1.WebBrowserShortcutsEnabled = false;
//打开IE打印机会话框
this.webBrowser1.ShowPrintDialog();
//打开IE的打印预览会话框
this.webBrowser1.ShowPrintPreviewDialog();
//打开IE的保存 会话框
this.webBrowser1.ShowSaveAsDialog();
}
#region 设置网页字段
/// <summary>
/// 设置网页字段
/// </summary>
/// <param name="strInput"></param>
private void SetHtmlElementValue(string strInput)
{
try
{
Clipboard.Clear();
Clipboard.SetDataObject(strInput);
IDataObject elementData = Clipboard.GetDataObject();
if (elementData.GetDataPresent(DataFormats.Text))
{
HtmlElement elem = this.webBrowser1.Document.ActiveElement;
elem.SetAttribute("value", strInput);
}
return;
}
catch (Exception ex)
{ }
}
#endregion
private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
SetHtmlElementValue("aaaaaaaaaaa");
}