如何刷新VB.NET上的WebBrowser1白色闪烁?

时间:2018-12-28 21:02:14

标签: vb.net

  

我每20秒呼叫我的页面一次,但是当我呼叫我的页面时,我看到了闪光。页面加载时是否可以避免闪烁?

Private Sub WebBrowser1_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(New Uri("http://metalrockpopradio.caramania.com/tuneefy4.php"))
Dim timer As New Timer()
timer.Interval = 20000
AddHandler timer.Tick, AddressOf WebBrowser1.Refresh
timer.Start()

2 个答案:

答案 0 :(得分:0)

有两个。新的重新加载完成后,显示新的控件并隐藏旧的控件。

或者,在页面上使用AJAX或类似内容重新加载内容。

答案 1 :(得分:0)

您可以执行以下操作:

  • 创建表单(此处称为Form1
  • 向其中添加一个PictureBox(在这里称为PictureBox1
  • 将PictureBox的大小设置为所需的大小,然后设置其SizeMode = Zoom
  • 将以下代码粘贴到窗体的代码部分文件(窗体上的F7)

Imports System.Net
Imports System.Windows.Forms

Public Class Form1
    Dim timer As System.Windows.Forms.Timer
    Private client As WebClient = New WebClient()

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        RefreshImage(Nothing, Nothing)
        timer = New System.Windows.Forms.Timer()
        AddHandler timer.Tick, AddressOf Me.RefreshImage
        timer.Interval = 5000
        timer.Start()
    End Sub

    Protected Sub RefreshImage(sender As Object, e As EventArgs)
        Dim HttpResource As String = client.DownloadString("http://metalrockpopradio.caramania.com/tuneefy4.php")
        Dim ParseStart As Integer = HttpResource.IndexOf("=") + 2
        HttpResource = HttpResource.Substring(ParseStart, HttpResource.LastIndexOf(ChrW(34)) - ParseStart)
        If PictureBox1.Image IsNot Nothing Then PictureBox1.Image.Dispose()
        PictureBox1.Load(HttpResource)
    End Sub

    Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        client.Dispose()
        timer.Dispose()
    End Sub
End Class