WebBrowser control auto refresh

后端 未结 2 420
臣服心动
臣服心动 2021-01-17 02:36

I want to make a program in Visual Studio 2008 in Visual Basic. It involves a web browser and I want to make it auto refresh and allow people to choose the time period in wh

相关标签:
2条回答
  • 2021-01-17 03:07

    From what I gather, it seems that you are trying to create a WinForms application in VB.NET. To accomplish your goal, you can:

    1. Create a NumericUpDown or Textbox control to allow users to select a refresh time period (you can decide whether you want this to be in seconds, minutes, or something else).
    2. Create a Timer object, and using the TextChanged event of the textbox or the ValueChanged event of the NumericUpDown control, set the entered value equal to the interval of the Timer.
    3. Create buttons that call the Timer's start and stop function, to allow the user to start and stop auto-refreshing.
    4. Subscribe to the Timer's Tick event and call the WebBrowser's Refresh method when the event is raised/fired.

    Here's some sample code.

    Public Class Form1
        Private Sub numInterval_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles numInterval.ValueChanged
            Timer1.Interval = numInterval.Value
        End Sub
    
        Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
            Timer1.Start()
    
        End Sub
    
        Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
            Timer1.Stop()
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            WebBrowser1.Refresh(WebBrowserRefreshOption.Completely)
        End Sub
    End Class
    

    As you can see, I have added event handlers to Timer1.Tick and numInterval.ValueChanged.

    0 讨论(0)
  • 2021-01-17 03:10

    I would make a setting in "Properties > Settings" Tab for the interval you want to set for this I am going to name it unlimitRefresh and make sure it is a string and set the scope to user. After that I would make the interval options a DropDown button with every interval you want set and then I would make a two timers and for the first one I would set the interval to 1 and have it find out what the settings tab says. Then for the code for that I would type:

    Timer2.Interval = My.Settings.unlimitRefresh
    

    And then for timer one set that to whatever you want it on. Then for the code I would type:

    WebBrowser1.Refresh()
    

    After you are done just go to your dropdown button and double click each button for code and after that you type in:

    My.Settings.unlimitRefresh = TYPE-THE-INTERVAL-HERE 
    

    Example:

    My.Settings.unlimitRefresh = 100
    

    After that it should work fine.

    Also, I do realize this post is really old but just in case somebody does view it.

    0 讨论(0)
提交回复
热议问题