locked
Lines in textbox RRS feed

  • Question

  • Hello! So, i am making a proram(just for fun and knowledge) that will navigate to each website in the textbox. So, if text in my textbox is:

    http://facebook.com/

    http://google.com/

    http://msdn.microsoft.com/

    http://rghost.ru/

    Then, when i click the button, my first webbrowser(webbrowser1) will navigate to facebook, second browser(webbrowser2) will navigate to google, and etc.

    How would i make that?

    Sorry for my mest up English.

    Wednesday, August 29, 2012 4:21 AM

Answers

  • Either set the Url property of the WebBrowser or call its Navigate method.
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 7:50 AM
  • What about creating a new Process:

    Process.Start(textBox1.Text);

    or by defining the browser:

    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("IExplore.exe", textBox1.Text);
    System.Diagnostics.Process.Start(startInfo);
    startInfo = null;


    Mitja


    • Edited by Mitja Bonca Wednesday, August 29, 2012 8:06 AM
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 8:06 AM
  • Put a button - button1 in your form and use this code:

            private void button1_Click(object sender, EventArgs e)
            {
                int left = 100;
                foreach (Control c in Controls)
                {
                    if (c.Tag.ToString() == "MyTextBox")
                    {
                        left += 200;
                        WebBrowser wb = new WebBrowser();
                        wb.Left = left;
                        Controls.Add(wb);
                        wb.Navigate(c.Text);
                    }
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                button1.Tag = "Not a TextBox";
                // Create 3 text boxes for demo
                for (int i = 0; i < 3; i++)
                {
                    TextBox tb = new TextBox();
                    tb.Tag = "MyTextBox";
                    tb.Top = i * 40; // Make them appear one after the other
                    Controls.Add(tb);
                }
            }
    

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    • Proposed as answer by Noam B Thursday, August 30, 2012 10:44 AM
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 10:57 AM
  • You can pass your url from text boxes to launch the browser:

    Process.Start("IExplore.exe", url)

    cheers!!!

    Vatsa

    www.objectiveprogramming.com

    if helpfull please "Vote as Helpful",mark as "Answers" if it answers your question.

    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 8:09 AM
  • Given that your TextBox text property contains a valid  URL and you are using a default browser you could also do as follows:

    string url = this.txtBox1.Text;
    
    System.Diagnostics.Process.Start(url);
    

    Better to place it into "try-catch" statement!

    Kind regards,

    wizend

    • Proposed as answer by Prathap Kumar Wednesday, August 29, 2012 8:34 AM
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 8:11 AM

All replies

  • Either set the Url property of the WebBrowser or call its Navigate method.
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 7:50 AM
  • What about creating a new Process:

    Process.Start(textBox1.Text);

    or by defining the browser:

    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("IExplore.exe", textBox1.Text);
    System.Diagnostics.Process.Start(startInfo);
    startInfo = null;


    Mitja


    • Edited by Mitja Bonca Wednesday, August 29, 2012 8:06 AM
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 8:06 AM
  • You can pass your url from text boxes to launch the browser:

    Process.Start("IExplore.exe", url)

    cheers!!!

    Vatsa

    www.objectiveprogramming.com

    if helpfull please "Vote as Helpful",mark as "Answers" if it answers your question.

    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 8:09 AM
  • Given that your TextBox text property contains a valid  URL and you are using a default browser you could also do as follows:

    string url = this.txtBox1.Text;
    
    System.Diagnostics.Process.Start(url);
    

    Better to place it into "try-catch" statement!

    Kind regards,

    wizend

    • Proposed as answer by Prathap Kumar Wednesday, August 29, 2012 8:34 AM
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 8:11 AM
  • Put a button - button1 in your form and use this code:

            private void button1_Click(object sender, EventArgs e)
            {
                int left = 100;
                foreach (Control c in Controls)
                {
                    if (c.Tag.ToString() == "MyTextBox")
                    {
                        left += 200;
                        WebBrowser wb = new WebBrowser();
                        wb.Left = left;
                        Controls.Add(wb);
                        wb.Navigate(c.Text);
                    }
                }
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                button1.Tag = "Not a TextBox";
                // Create 3 text boxes for demo
                for (int i = 0; i < 3; i++)
                {
                    TextBox tb = new TextBox();
                    tb.Tag = "MyTextBox";
                    tb.Top = i * 40; // Make them appear one after the other
                    Controls.Add(tb);
                }
            }
    

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    • Proposed as answer by Noam B Thursday, August 30, 2012 10:44 AM
    • Marked as answer by Bob Shen Thursday, September 6, 2012 9:10 AM
    Wednesday, August 29, 2012 10:57 AM