Vb.net 更新Picturebox图像
我使用图片框作为另一个winform上webbrowser控件的“预览”屏幕。除此之外,为了更新picturebox控件,我发现代码需要运行两次(双击按钮),链接到下面的代码。你知道为什么picturebox没有在第一次更新时显示新导航的页面吗Vb.net 更新Picturebox图像,vb.net,picturebox,Vb.net,Picturebox,我使用图片框作为另一个winform上webbrowser控件的“预览”屏幕。除此之外,为了更新picturebox控件,我发现代码需要运行两次(双击按钮),链接到下面的代码。你知道为什么picturebox没有在第一次更新时显示新导航的页面吗 Private Sub mOutput_Click(sender As Object, e As EventArgs) Handles mOutput.Click If Not mFiles.SelectedItem Is Nothing T
Private Sub mOutput_Click(sender As Object, e As EventArgs) Handles mOutput.Click
If Not mFiles.SelectedItem Is Nothing Then
Formloading.fDisplay.WebBrowser1.Navigate(folderloc.ToString & "\" & mFiles.SelectedItem.ToString)
End If
Dim Bounds As System.Drawing.Rectangle
Dim outputscreen As System.Drawing.Bitmap
Dim graph As System.Drawing.Graphics
Dim LO As Integer = 0
With Bounds
.Height = fDisplay.WebBrowser1.Height
.Width = fDisplay.WebBrowser1.Width
.X = Formloading.fDisplay.Location.X
.Y = Formloading.fDisplay.Location.Y
.Size = Formloading.fDisplay.Size
End With
outputscreen = New System.Drawing.Bitmap(Bounds.Width, Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
graph = System.Drawing.Graphics.FromImage(outputscreen)
graph.CopyFromScreen(Bounds.X, Bounds.Y, 0, 0, Bounds.Size, Drawing.CopyPixelOperation.SourceCopy)
PictureBox1.Image = outputscreen
End Sub
调用WebBrowser.Navigate()时,浏览器只会开始导航到url。需要一段时间,当它是一个文件时眨眼。但是眨眼的时间不够短,你的截图太快了。因为浏览器已经显示了文件内容,所以第二次单击就可以了。您需要将屏幕截图代码移动到WebBrowser.DocumentCompleted事件的事件处理程序中。嗨,Hans,谢谢您的回复。。。我最终解决了这个问题,转而使用带有标签的表单,而不是webrowser。