Hello,
Firstly to display a web browser, you will have to add a webbrowser component to your Form.
To do that:
Quote:
1> Open the toolbox
2> Now go to the common controls section.
3> In that you will find the web browser component.
4> Using the mouse add it to the windows form.
The next thing is:
Quote:
1>Add a listbox to the windows form.
2> Also add a button to the windows form
Now look at the code below:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void bind_listbox()
{
listBox1.DataSource = new List<string>() {"codeproject","google"}; ///populate the list box with the sites you want to surf
}
/// <summary>
/// Please note that when you add a web browser component then a text area will appear on your form itself where you will be able to browse to different sites. As shown in the code below.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
switch (button1.Text) ///using the switch case navigate to the web sites
{
case "codeproject":
webBrowser1.Navigate("http://www.codeproject.com/");
break;
case "google":
webBrowser1.Navigate("https://www.google.co.in/");
break;
}
}
private void Form1_Load(object sender, EventArgs e)
{
bind_listbox(); ///binding the listbox on form load. However in case of larger number of entries, form loading may take time and application may become unresponsive.
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
button1.Text = listBox1.SelectedItem.ToString(); ////this event is fired when you select an item from the list box.
}
}
Now Try this out.
Please note:
I have mapped the web site browsing function to just one button. If you want you can do it using multiple buttons(according to what i read from your question).
Thanks,