首页 > 解决方案 > VB.NET 如何获取 BackgroundImage 的名称?

问题描述

我有一个函数可以为新表单提供 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:'重载解析失败,因为无法使用这些参数调用公共'=':'公共共享运算符 =(a 作为字符串,b 作为字符串)作为布尔值':参数匹配参数'a'无法从'转换位图'到'字符串'。'"

如果我将其从“If Tag = “Net” Then”更改为“If Tag = My.Resources.WFN Then”,那么我会得到“'Operator '=' is not defined for type 'Bitmap' and type 'Bitmap'。” “ 错误

我需要的是 BackgroundImage 的实际名称

谢谢您的帮助

标签: vb.net

解决方案


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


推荐阅读