这个是我的一个程序里面的 MDI窗口的背景 vb.net写的 '获取并绘制MDI窗口的背景图 Private Sub getmdipic() Dim mycontrol As Control Dim bgmdiclient As MdiClient Dim myimage As Bitmap Dim bgimage As Bitmap '路径 Dim imgurl As String Dim myGraphics As Graphics '绘制方式 Dim drawtype As String Try drawtype = func.GetKeyVal(inipath, "BgImg", "showtype") imgurl = Application.StartupPath & "\bgimg\" & func.GetKeyVal(inipath, "BgImg", "img") For Each mycontrol In Me.Controls If mycontrol.GetType.ToString = "System.Windows.Forms.MdiClient" Then bgmdiclient = mycontrol Exit For End If Next bgimage = Bitmap.FromFile(imgurl) Select Case drawtype '平铺方式 Case "1" myimage = New Bitmap(bgmdiclient.ClientSize.Width, bgmdiclient.ClientSize.Height) myGraphics = Graphics.FromImage(myimage) myGraphics.DrawImage(bgimage, 0, 0, myimage.Width + 1, myimage.Height + 1) bgmdiclient.BackgroundImage = myimage myGraphics.Dispose() '拉伸方式 Case "2" bgmdiclient.BackgroundImage = bgimage Case Else bgmdiclient.BackgroundImage = bgimage End Select Catch ex As Exception Exit Sub End Try End Sub
MDI窗口的背景 vb.net写的
'获取并绘制MDI窗口的背景图
Private Sub getmdipic()
Dim mycontrol As Control
Dim bgmdiclient As MdiClient
Dim myimage As Bitmap
Dim bgimage As Bitmap
'路径
Dim imgurl As String
Dim myGraphics As Graphics
'绘制方式
Dim drawtype As String Try
drawtype = func.GetKeyVal(inipath, "BgImg", "showtype")
imgurl = Application.StartupPath & "\bgimg\" & func.GetKeyVal(inipath, "BgImg", "img")
For Each mycontrol In Me.Controls
If mycontrol.GetType.ToString = "System.Windows.Forms.MdiClient" Then
bgmdiclient = mycontrol
Exit For
End If
Next
bgimage = Bitmap.FromFile(imgurl)
Select Case drawtype
'平铺方式
Case "1"
myimage = New Bitmap(bgmdiclient.ClientSize.Width, bgmdiclient.ClientSize.Height)
myGraphics = Graphics.FromImage(myimage)
myGraphics.DrawImage(bgimage, 0, 0, myimage.Width + 1, myimage.Height + 1)
bgmdiclient.BackgroundImage = myimage
myGraphics.Dispose()
'拉伸方式
Case "2"
bgmdiclient.BackgroundImage = bgimage
Case Else
bgmdiclient.BackgroundImage = bgimage
End Select
Catch ex As Exception
Exit Sub
End Try
End Sub