0

i have got a multiline textBox1 and webbrowser1

when the the document complete, i want the program to fill an element with one line then do something then refill the same element with the second line etc............

the code is:

       HtmlEleme ele = webBrowser1.Document.GetElementById("element ID");
       if(ele != null)
                ele.InnerText = textBox1.Lines[0];

how could i make this ( for while or.....) and how???

and where i should put the code ?

Alfabravo
  • 7,493
  • 6
  • 46
  • 82
Manar Al Saleh
  • 365
  • 1
  • 2
  • 11

1 Answers1

1

If your browser will load page when you click the button you can follow this:

 bool loaded;
void Operate()
{
            string[] lines = TextBox1.Text.Split('\n');
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

            for (int i = 0; i < lines.Length; i++)
            {
                loaded = false;
                HtmlElement ele = webBrowser1.Document.GetElementById("element ID");
                ele.InnerText = lines[i];
                //click a button here
                HtmlElement elmbutton = webBrowser1.Document.GetElementById("ButtonID");
                elmbutton.InvokeMember("click");
                //here wait for web browser navigate.
                while (!loaded)
                {
                    System.Threading.Thread.Sleep(10);
                   Application.DoEvents();
                }
            }

        }

        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            loaded = true;
        }

On the other hand I must warn you about the drawbacks of Application.DoEvents()

aliassce
  • 1,197
  • 6
  • 19