vb.net - 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 的实际名称
谢谢您的帮助
解决方案
var bmp = new Bitmap(WindowsFormsApplication1.Properties.Resources.myimage); 使用位图发送到图像
推荐阅读
- python - 烧瓶解码数据
- android - 如何使 sqlite 数据库中的 url 适应 imageview
- javascript - 防止用户在 HTML 中看到视频 URL?
- vb.net - Applycurrent values 仅显示第一个值
- php - 多维数组值中的 JSON 对象值(Google GEO 数据)
- ansible - 如何在 Ansible 中执行交替角色?
- svg - createjs中形状的SVG路径
- node.js - NestJS cookie-parser 在 e2e 测试期间不是函数错误
- sql - 需要将查询从 Oracle 转换为 SQL Server,并且需要转换 ListAgg
- java - 在 python 子进程中发送一个字符串作为参数