VB.NET如何获取BackgroundImage的名称?

时间:2019-03-07 19:54:55

标签: vb.net

我有一个函数,它将为新表单提供BackgroundImage:

    Public Shared WaitForNet As Image = My.Resources.WFN
    Public Shared WaitForDB As Image = My.Resources.WFS
    Public Shared Function GetWaitFormBG(code As String) As Image
    Dim img As Image = Nothing

    Select Case code
        Case "Net"
            img = WaitForNet
        Case "DB"
            img = WaitForDB
    End Select

    Return img
End Function

在Sub中,我有:

Public Shared Sub FrmWaitLoad(ByVal R As String)
    Dim WF As New WaitForm

    WF.Tag = GetWaitFormBG(R)
    WF.Show()
End Sub

在WaitForm加载中,我有:

Private Sub WaitForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    BackgroundImage = Tag
        If Tag = "Net" Then
        Do Until Net = True
            Application.DoEvents()
        Loop
    End If

    If Tag = "DB" Then

        T = 5

        Timer1.Interval = 60000
        Timer1.Enabled = True

        Do Until DB = True
            Application.DoEvents()
        Loop

        Timer1.Stop()
        Close()
    End If
End Sub

但是我收到一条错误消息:

“ System.InvalidCastException:'重载解析失败,因为无法使用这些参数调用Public'=':     '公共共享运算符=(a作为字符串,b作为字符串)作为布尔值':         参数匹配的参数'a'无法从'位图'转换为'字符串'。'“

如果我将其从“ If Tag =“ Net”然后”更改为“ If Tag = My.Resources.WFN然后”,那么我会得到“未为'位图'类型和'位图类型定义'运算符'=' '。'“错误

我需要的是BackgroundImage的实际名称

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

var bmp = new Bitmap(WindowsFormsApplication1.Properties.Resources.myimage); 使用位图发送到图像