我正在使用 C#(Microsoft Visual C# 2010 Express)开发一个简单的 Web 表单应用程序.
I am working on a simple web forms application with C# (Microsoft Visual C# 2010 Express).
我在表单上有两个文本框(textBox1、richTextBox1)、一个按钮(button1)和一个网络浏览器(webBrowser1).当我运行程序时,Web 浏览器会转到一个网页.在该页面上有两个输入字段,我想通过使用 textBox1 和 richTextBox1 中的文本单击 button1 来自动填充.
I have two text boxes (textBox1, richTextBox1) a button (button1) and a web browser (webBrowser1) on the form. The web browser goes to a web page when I run the program. On that page there are two input fields that I want to autofill with the click of the button1 using the text in textBox1 and richTextBox1.
您可以在该网页上看到输入字段的代码:
You can see the code of the input fields on that web page:
<input type="text" id="subject" tabindex="4" name="subject" value=""> <textarea class="composebody" tabindex="6" name="message" id="message" rows="20" cols="80"></textarea>我知道这很简单,但我对 C# 了解不多.任何想法如何编码?
I know this is very simple, but I don't have much knowledge about C#. Any ideas how I can code that?
谢谢.
推荐答案你需要写这个代码
webBrowser1.Document.GetElementById("subject").SetAttribute("value", subject.text);webBrowser1.Document.GetElementById("msg").SetAttribute("value",message.text );
webBrowser1.Document.GetElementById("subject").SetAttribute("value", subject.text); webBrowser1.Document.GetElementById("msg").SetAttribute("value",message.text );
并且需要调用这两行Webbrowser 的 DocumentCompleted 事件.
and need to call those two lines in DocumentCompleted event of webbrowser.
希望有帮助.
更多推荐
使用 C# 自动填充网页上的 2 个字段
发布评论