1
Well, here’s a possibility, using only basic things.
Create a array within the scope of the class (of form
in the case), in this array will be saved all sites in your "list" of sites. And create, also in the class scope, a variable that will keep saved what is the position of this array that is currently being accessed.
Let’s assume that by opening the form, the webBroser
will navigate to the first site in the list, ie the index zero of array.
string[] listaSites = new[] { "https://answall.com", "https://stackoverflow.com" };
int posicaoAtual = 0;
Then, in the clicks of the buttons you will validate the following:
On the button
Próximo
, will be captured the next site of the list, based on what is already being shown to the user (posicaoAtual
).a. If there is a next site on the list (
posicaoAtual
is smaller than the last index of array, that is, the size of array subtracting 1), it will be accessed.b. If there is no next site (
posicaoAtual
is exactly the last index of array) nothing will happen.On the button
Anterior
, will be captured the previous site, also based on what is already being shown.a. If there is a previous site in the list (if
posicaoAtual
greater than 0), the same will be accessed.b. If there is no previous website (if
posicaoAtual
for 0), nothing will happen.
The code will basically look like this
public class Form1: Form
{
string[] listaSites = new[] { "https://answall.com", "https://stackoverflow.com" };
int posicaoAtual = 0;
public Form1()
{
InitializeComponents();
}
private static void btAnterior_Click(object sender, EventArgs e)
{
if(posicaoAtual - 1 >= 0)
{
posicaoAtual -= 1;
// (^-) Trocar a posição atual para a anterior
webBrowser.Navigate(listaSites[posicaoAtual]);
// (^-) Navegar para o respectivo site
}
}
private static void btProximo_Click(object sender, EventArgs e)
{
if(posicaoAtual + 1 < listaSites.Length)
{
posicaoAtual += 1;
// (^-) Trocar a posição atual para a próxima
webBrowser.Navigate(listaSites[posicaoAtual]);
// (^-) Navegar para o respectivo site
}
}
}
I think the question is very generic Sergio, let’s go by parts.. first you know how to load the url for webbrowser? then use the next buttons with the urls array?.. etc
– Dorathoto
Look, I have a notion... webBrowser1.Navigate("www.site.com"); to navigate but I have no idea how to do this xD array business
– Sérgio Wilker