在C#中简单的浏览器控件 [英] Simple Browser Control in C#

查看:230
本文介绍了在C#中简单的浏览器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的C#的WinForms AP界面污物对于不得不做很多简单的网络查找员工。目前,它加载5个网站,并把搜索词到剪贴板。员工则必须粘贴搜索项在每个网站的搜索文本框,然后回车。是否有进入的数据对他们来说一个简单的方法?搜索文本框通常集中在网站加载,我不能找到一种方法来检测时,在页面加载或如何将数据发送到窗口。

I have a simple C# WinForms Crud AP for employees that have to do a lot of simple web lookups. Currently it loads 5 websites and puts a search term into the clipboard. The employee then has to paste the search term into the search textbox on each of the sites and hit enter. Is there a simple way to enter the data for them? The search textbox usually has focus when the sites load, I just cannot find a way to detect when the page has loaded or how to send the data to the window.

看来,从这些有用的答案,就像我会对此错误的方式。我是用我的好朋友的帮助下,谷歌先生

It looks, from these helpful answers, like I was going about this the wrong way. I was using code found with the help of my good friend, Mr. Google

System.Diagnostics.Process.Start("www.website.com");
Clipboard.SetText(textBox1.Text, TextDataFormat.Text);

我将在本周做更多的研究,WebBrowser控件

I will do some more research this week on the webbrowser control

推荐答案

您可以使用web浏览器的DocumentCompleted事件在页面完成加载后发出通知。

You can use WebBrowser's DocumentCompleted event to be notified when the page has finished loading.

如果你输入你的文本都有一个唯一的ID的文本框,你可以用WebBrowser.Document.GetElementById:

If the textbox you're entering your text into has a unique id, you can use WebBrowser.Document.GetElementById:

webBrowser.Document.GetElementById("some_id").InnerText = theSearchText;

的getElementById返回的HtmlElement (或空,如果没有找到该元素)。请注意,.InnerText可能不适用于所有元素类型的工作,另外还有的innerHTML和很多其他的特性,我建议你用的的HtmlElement 课前决定如何使用它。

GetElementById returns an instance of HtmlElement (or null, if the element wasn't found). Note that ".InnerText" might not work for all element types, there's also InnerHtml and lots of other properties, I'd recommend playing around with the HtmlElement class before deciding how to use it.

让我知道,如果你没有一个唯一的ID为元素,还有很多otherways找到一个元素。包括经由document.body的用暴露的DOM

Let me know if you don't have a unique id for the element, there's lots of otherways to find an element. including using the exposed DOM via Document.Body.

这篇关于在C#中简单的浏览器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆