Re: Controlling IE, submitting forms
Vince P <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.winforms |
|---|---|
| Message-ID | <001b01c79a5a$525a1d00$f70e5700$@net> |
I made a Windows Form app that invokes a Spell checker when the Browser control is browsing certain webpages and I enter comments , like on a discussion board. It watches for when I leave the text box in the webpage and then does the spell check. This doesn't directly answer your question, but you can see how I reference forms and elements.
So the first thing I do is scan a new web page after it loads:
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
if (this.webBrowser1.Document != null)
{
this.htmlDoc = this.webBrowser1.Document; // HtmlDocument
if (this.htmlDoc != null)
{
if (this.htmlDoc.Forms["commentform"] != null && this.htmlDoc.Forms["commentform"].Children != null)
{
HtmlElementCollection elCol = this.htmlDoc.Forms["commentform"].Children.GetElementsByName("comment");
webTextBox = this.htmlDoc.Forms["commentform"].Children["comment"]; // HtmlElement
if (webTextBox == null)
{
if (this.htmlDoc != null && this.htmlDoc.Forms.Count >= 2 && this.htmlDoc.Forms[1].Children.Count >= 6 && this.htmlDoc.Forms[1].Children[5].Children.Count >= 3)
{
webTextBox = this.htmlDoc.Forms[1].Children[5].Children[2];
}
}
if (webTextBox != null)
{
webTextBox.KeyPress += new HtmlElementEventHandler(webTextBox_KeyPress);
webTextBox.LostFocus += new HtmlElementEventHandler(webTextBox_LostFocus);
}
}
}
}
void webTextBox_LostFocus(object sender, HtmlElementEventArgs e)
{
if (!inFormTextEvent && !inWebTextEvent)
{
if (string.Compare(webTextBox.InnerText, richTextBox1.Text, StringComparison.Ordinal) != 0)
{
try
{
inFormTextEvent = true;
inWebTextEvent = true;
this.richTextBox1.Text = this.webTextBox.InnerText;
}
finally
{
inFormTextEvent = false;
inWebTextEvent = false;
}
}
if (!string.IsNullOrEmpty(webTextBox.InnerText))
{
if (DialogResult.OK == this.ultraSpellChecker1.ShowSpellCheckDialog(this.richTextBox1))
{
}
}
}
}
-
THESE are the times that try men's souls. The summer soldier and the sunshine patriot will, in this crisis, shrink from the service of their country; but he that stands by it now, deserves the love and thanks of man and woman. Tyranny, like hell, is not easily conquered; yet we have this consolation with us, that the harder the conflict, the more glorious the triumph.
> -----Original Message-----
> From: Discussion forum for developers using Windows Forms to build apps
> and controls [mailto:[email protected]] On Behalf Of
> Chris Bordeman
> Sent: Wednesday, May 09, 2007 21:31
> To: [email protected]
> Subject: [DOTNET-WINFORMS] Controlling IE, submitting forms
>
> Hi all. I want to embed an IE control in a WinForms app, fill in form
> fields automatically, proceeding to the next page automatically,
> through
> several pages.
>
> What are some reliable ways to accomplish this? Thanks!
>
> Chris B.