我只是要从数据库中提取它。
BackgroundImage = My.Resources.splash1
的作品,但我找不到一个好的方法来改变它,除了有一个巨大的选择案例的功能。
Select Case iSplash
Case 1
Return My.Resources.splash1
Case 2
Return My.Resources.splash2
etc...
所以我最终的解决方案,万一别人永远需要做到这一点:
Function splashimage(ByVal int As Integer) As System.Drawing.Image
On Error GoTo sError
Dim rSelect As New ADODB.Recordset
Dim sSql As String = "Select * From tblSplashImages Where SplashID = " & int
Dim ms As IO.MemoryStream
Dim img As System.Drawing.Image
img = Nothing
With rSelect
.Open(sSql, MyCn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic)
If Not .EOF Then
ms = New IO.MemoryStream(CType(.Fields!Data.Value, Byte()))
img = System.Drawing.Image.FromStream(ms)
Else
img = My.Resources.tracks1
End If
.Close()
End With
Return img
sError:
MsgBox(ErrorToString, MsgBoxStyle.Exclamation)
End Function
这引出了一个问题,在那里你觉得图像列表保持自己的形象? – Blindy 2011-03-08 20:50:49
呃,是的,我现在看到了,不知道为什么我以前没有注意到。 My.Resources.splash1可以工作,但是如果我有30个闪屏图像,并且在我的资源中有几十个其他图像(按钮图标等),我该如何随机抽取闪屏图像,并确保我没有得到按钮图标?这是ImageList会很好的地方。如果您知道某种方式,请将其输入为答案。 – AndyD273 2011-03-08 21:36:33