WebBrowser получение домашней страницы в TextBox и её изменение - C#
Формулировка задачи:
Здравствуйте!
Подскажите пожалуйста, как мне вывести URL(адрес) домашней страницы в компонент TextBox, а так же, потом её изменить на страницу, введённую в TextBox?
Я пытался отобразить URL домашней страницы через:
Весь код браузера:
MessageBox.Show(WebBrowser1.Url.ToString());//Выдаётся крит. ошибка MessageBox.Show(Convert.ToString(WebBrowser1.Url));//Аналогично...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Браузер_на_C_Sharp
{
public partial class Form1 : Form
{
WebBrowser WebBrowser1 = new WebBrowser();
Button Button1 = new Button();
Timer Timer1 = new Timer();
TextBox TextBox1 = new TextBox();
public Form1()
{
InitializeComponent();
this.Width = 800;
this.Height = 400;
this.Text = "C# WebBrowser";
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.StartPosition = FormStartPosition.CenterScreen;
this.WindowState = FormWindowState.Maximized;
this.Controls.Add(WebBrowser1);
{
WebBrowser1.Left = 0;
WebBrowser1.Top = 25;
WebBrowser1.Width = this.ClientSize.Width;
WebBrowser1.Height = this.ClientSize.Height - 25;
WebBrowser1.GoHome();
}
this.Controls.Add(Button1);
{
Button1.Width = 75;
Button1.Height = 25;
Button1.Left = 25;
Button1.Top = 0;
Button1.Text = "HOME";
Button1.Click += new EventHandler(Button1Click);
}
this.Controls.Add(TextBox1);
{
TextBox1.Width = this.ClientSize.Width - ((this.ClientSize.Width / 2));
TextBox1.Height = 25;
TextBox1.Left = this.ClientSize.Width - TextBox1.Width - 4;
TextBox1.Top = 2;
}
Timer1.Tick += new EventHandler(Timer1Tick);
Timer1.Interval = 5;
Timer1.Start();
}
void Timer1Tick(object senter, EventArgs e)
{
WebBrowser1.Width = this.ClientSize.Width;
WebBrowser1.Height = this.ClientSize.Height - 25;
TextBox1.Width = this.ClientSize.Width - ((this.ClientSize.Width / 2));
TextBox1.Left = this.ClientSize.Width - TextBox1.Width - 4;
}
void Button1Click(object senter, EventArgs e)
{
WebBrowser1.GoHome();
}
}
}Решение задачи: «WebBrowser получение домашней страницы в TextBox и её изменение»
textual
Листинг программы
public partial class Form1 : Form
{
WebBrowser WebBrowser1 = new WebBrowser();
Button Button1 = new Button();
TextBox TextBox1 = new TextBox();
string homepage = "www.google.ru";
public Form1()
{
InitializeComponent();
this.Controls.Add(WebBrowser1);
WebBrowser1.Navigated += NavigateHandler;
WebBrowser1.Navigate(homepage);
this.Controls.Add(Button1);
this.Controls.Add(TextBox1);
}
void Button1Click(object senter, EventArgs e)
{
WebBrowser1.Navigate(TextBox1.Text);
}
void NavigateHandler(object sender, WebBrowserNavigatedEventArgs e)
{
TextBox1.Text = e.Url.ToString();
}
}