2011-03-08 78 views
0

我的程序有一个启动画面,我想每次程序打开时都会有一个背景图像。
我看到这样做的一种方式是从ImageList中加载它,但它的最大图像大小为256x256。
初始屏幕是498 x 305,这意味着我需要找到除ImageList以外的其他东西,但希望能够用类似的功能来组织图像。
我的确尝试将它们放入资源中,但无法让它设置背景而没有错误,并且我不希望将30张图像混乱放置。在运行时在VB.Net中设置一个Splashscreen背景图片

+0

这引出了一个问题,在那里你觉得图像列表保持自己的形象? – Blindy 2011-03-08 20:50:49

+0

呃,是的,我现在看到了,不知道为什么我以前没有注意到。 My.Resources.splash1可以工作,但是如果我有30个闪屏图像,并且在我的资源中有几十个其他图像(按钮图标等),我该如何随机抽取闪屏图像,并确保我没有得到按钮图标?这是ImageList会很好的地方。如果您知道某种方式,请将其输入为答案。 – AndyD273 2011-03-08 21:36:33

回答

1

我只是要从数据库中提取它。

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