自动代理切换器WInform(C#)

时间:2018-12-26 09:51:13

标签: c# winforms

我是 C#的新手,我正在尝试使用它来构建应用。

在我的应用中,可以选择在网络浏览器上使用代理。 我已经找到了一种在Web浏览器上使用代理的方法。 工作原理:用户粘贴一个IP:端口代理,然后单击开始按钮,应用程序告诉Web浏览器使用指定的代理服务器。 >

!问题:问题是我希望该应用在一定时间后切换代理。

我所拥有的概念是:textbox,用户可以在其中粘贴代理列表,然后在用户单击“开始”按钮后,该应用程序将告诉网络浏览器在第一行使用代理。

(让我们说)30秒后,它将自动切换到第二行,依此类推,直到用户单击停止按钮为止。

基本上,它将在一段时间后垂直切换到新行。

谢谢。

1 个答案:

答案 0 :(得分:0)

  1. 添加计时器控件。

请参考以下代码

List<string> lstIpAddress = new List<string>();
int nCount = 0;

private void Form1_Load(object sender, EventArgs e)
{
   timer1.Interval = 30000;
}

 private void button1_Click(object sender, EventArgs e)
 {
        string strIp = textBox1.Text;
        if (strIp.Length > 0)
        {
            lstIpAddress = strIp.Split(',').ToList();
            for (int nlstItem = 0; nlstItem < lstIpAddress.Count; nlstItem++)
            {
                listBox1.Items.Add(lstIpAddress[nlstItem]);
            }
            //Pass the IP to Web Browser
            label2.Text = listBox1.Items[nCount].ToString();
            nCount++;
        }
        timer1.Start();
 }

 private void timer1_Tick(object sender, EventArgs e)
 {
        timer1.Stop();
        //Pass the IP to Web Browser
        label2.Text = listBox1.Items[nCount].ToString();
        timer1.Start();
 }

IP Address