如何在 VB.NET 上刷新 WebBrowser1 不闪烁? [英] How do i refresh WebBrowser1 whitout flickering on VB.NET?
本文介绍了如何在 VB.NET 上刷新 WebBrowser1 不闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我每 20 秒调用一次我的页面,但是当我调用我的页面时,我看到了一个闪光.是否可以避免页面加载时的闪烁?
I call my page every 20 seconds but when i call my page i see a flash. Is it possible to avoid the flickering when the page load?
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()
推荐答案
你可以这样做:
- 创建一个表单(这里称为
Form1
) - 向其中添加一个图片框(此处称为
PictureBox1
) - 将图片框的大小设置为您想要的大小并设置其
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
这篇关于如何在 VB.NET 上刷新 WebBrowser1 不闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文