使用timer vb.net从列表框中选择下一个代理

时间:2017-06-07 20:33:25

标签: vb.net

嗨,启动一个新的应用程序来生成流量,我有3个列表框,一个用于推荐链接,一个用于代理,一个用于代理。 我的问题是我已经将树定时器添加到我的表单中,我需要每隔10秒更改文本框上的引用链接,例如 我该如何存档? 这是我的代码

Imports System.Runtime.InteropServices
Imports System.Net
Imports System
Public Class Form3
Dim FILE_NAME As String = "C:\proxy.txt"
Dim x As Integer
Dim rfe As Integer
Dim prx As Integer
Dim users As Integer
Dim label As String
Public proxy(2000) As String
Public index As Integer = 0
Public max_proxys As Integer = 0
Dim a As String
Dim start_check As Integer = 0
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function
Public Structure Struct_INTERNET_PROXY_INFO
    Public dwAccessType As Integer
    Public proxy As IntPtr
    Public proxyBypass As IntPtr
End Structure
Private Sub UseProxy(ByVal strProxy As String)
    Const INTERNET_OPTION_PROXY As Integer = 38
    Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

    Dim struct_IPI As Struct_INTERNET_PROXY_INFO

    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

    Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

    Marshal.StructureToPtr(struct_IPI, intptrStruct, True)

    Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Timer1.Enabled = True

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Timerreferrals.Enabled = True
    UseProxy(Label8.Text)
    Dim wr As HttpWebRequest = HttpWebRequest.Create(TextBox1.Text)
    wr.Referer = TextBox5.Text
    wr.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36"
    Dim resp As HttpWebResponse = wr.GetResponse
    WebBrowser1.Navigate(TextBox1.Text)
    Button1.Enabled = False
    Button2.Enabled = True
    Button3.Enabled = True
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    Timer1.Enabled = False
    Button1.Enabled = True
    Button2.Enabled = False
    Button3.Enabled = False
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

    x = x + 1
    If x = TextBox2.Text Then
        WebBrowser1.Refresh()
        x = 0
        Label4.Text = Val(Label4.Text) + 1

    End If
End Sub

Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TextBox2.Text = 10
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Label8.Text = (TextBox3.Text & ":" & TextBox4.Text)
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then


        Dim path As String = OpenFileDialog1.FileName

        ListBox1.Items.AddRange(System.IO.File.ReadAllLines(path))

    End If

End Sub

Private Sub Label13_Click(sender As Object, e As EventArgs) Handles Label13.Click
    ListBox1.Items.Clear()

End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    If OpenFileDialog2.ShowDialog = Windows.Forms.DialogResult.OK Then


        Dim path As String = OpenFileDialog2.FileName

        ListBox2.Items.AddRange(System.IO.File.ReadAllLines(path))

    End If
End Sub

Private Sub Label14_Click(sender As Object, e As EventArgs) Handles Label14.Click
    ListBox2.Items.Clear()

End Sub

Private Sub Label15_Click(sender As Object, e As EventArgs) Handles Label15.Click
    ListBox4.Items.Clear()

End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    If OpenFileDialog3.ShowDialog = Windows.Forms.DialogResult.OK Then


        Dim path As String = OpenFileDialog3.FileName

        ListBox4.Items.AddRange(System.IO.File.ReadAllLines(path))

    End If
End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timerreferrals.Tick
    rfe = rfe + 1
    Dim counthit = 0
    TextBox5.Text = ListBox1.Text
    Label17.Text = rfe
    Timerreferrals.Interval = 1000
    Dim sb As New System.Text.StringBuilder()
    If rfe = TextBox6.Text Then
        For Each o As Object In ListBox1.Items
            'sb.AppendLine(o)
            'TextBox5.Text = sb.ToString
            ' rfe = 0
            counthit = counthit + 1

        Next
        ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1


        TextBox5.Text = ListBox1.Text
        rfe = 0
    End If




    If TextBox6.Text = "" Then
        Return

    End If


End Sub
End Class

1 个答案:

答案 0 :(得分:0)

  

我的问题是我已经设法让每次定时器完成   从列表框中更改当前项目,但是文件最终会成为列表框   项目的错误超出范围...我怎么能检测到有没有   没有更多的项目,再次第一次

知道......所以改变:

ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1

类似于:

If Me.ListBox1.SelectedIndex < Me.ListBox1.Items.Count - 1 Then
    Me.ListBox1.SelectedIndex = Me.ListBox1.SelectedIndex + 1
Else
    Me.ListBox1.SelectedIndex = 0
End If