如果图像无效则隐藏图片框

Hide Picturebox if image is invalid

我正在使用 Telerik 报告工具创建报告,上面有一些图像。我使用来自客户端的 URL 在图片框中显示图像,但在某些情况下给定的 URL 无效,因此它将在报告中显示错误消息。我只想在图像不可用时隐藏图片框,这样错误就不会出现在报告中。我该怎么做?提前致谢:)

在您的网站上执行网络请求。 例如:

Public Sub Run()
    Dim myReportImage As Image = GetControl("ReportImage")
    myReportImage.Visible = CheckWebImage()
    ' or
    myReportImage.Enabled = CheckWebImage()
End Sub

Private Function CheckWebImage() As Boolean
    Dim url As New System.Uri("http://www.url.com/yourImage.jpg")
    Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
    Dim response As System.Net.WebResponse

    Try
        response = req.GetResponse()
        response.Close()
        request = Nothing
        Msgbox("Website Found!")
        Return True
    Catch ex As Exception
        request = Nothing
        Msgbox("Website not found. Check the url and internet connection")
        Return False
    End Try
End Sub