By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,550 Members | 918 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,550 IT Pros & Developers. It's quick & easy.

set back ground image to stretch

P: n/a
how can i set a back ground image property on an MDI main form to stretch?
Mar 23 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi again,

in .net 2003 you have to resize the image your self via code, below is an
example that resizes the image and keeps the correct proportions, it
shouldn't be to hard to modify the code so the image stretches over the
entire form ignorig the proportions. This in fact would be less code then
the sample.

Hope this helps

Greetz, Peter

Private Sub loadimage(ByVal myFileName As String)
Try
Dim imgOrg As Bitmap
Dim imgShow As Bitmap
Dim g As Graphics

Dim delenDoor, delenDoorHO, delenDoorBR As Double
'delenDoor = divide by
'delenDoorHO = divide by height
'delenDoorBR = divide by width

imgOrg = DirectCast(Bitmap.FromFile(myFileName), Bitmap)

'Get the forms' dimensions
delenDoorBR = imgOrg.Width / Me.ClientSize.Width
delenDoorHO = imgOrg.Height / Me.ClientSize.Height
If delenDoorBR > 1 Or delenDoorHO > 1 Then
If delenDoorBR > delenDoorHO Then
delenDoor = delenDoorBR
Else
delenDoor = delenDoorHO
End If

imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / delenDoor),
CInt(CDbl(imgOrg.Height) / delenDoor))
imgShow.SetResolution(imgOrg.HorizontalResolution,
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0,
CInt(CDbl(imgOrg.Width) / delenDoor), CInt(CDbl(imgOrg.Height) /
delenDoor)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
g.Dispose()
Else
imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
imgShow.SetResolution(imgOrg.HorizontalResolution,
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width,
imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, _ GraphicsUnit.Pixel)
g.Dispose()
End If
imgOrg.Dispose()

Me.BackgroundImage = imgShow
Me.Refresh()

Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'pass the image file you want to load
loadimage("c:\2_1024x768.jpg")
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"mcnewsxp" <mc******@mindspring.com> schreef in bericht
news:Ot**************@TK2MSFTNGP10.phx.gbl...
how can i set a back ground image property on an MDI main form to stretch?

Mar 24 '06 #2

P: n/a
what if the image was placed on the form in the design window?

Me.BackgroundImage ?

"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi again,

in .net 2003 you have to resize the image your self via code, below is an
example that resizes the image and keeps the correct proportions, it
shouldn't be to hard to modify the code so the image stretches over the
entire form ignorig the proportions. This in fact would be less code then
the sample.

Hope this helps

Greetz, Peter

Private Sub loadimage(ByVal myFileName As String)
Try
Dim imgOrg As Bitmap
Dim imgShow As Bitmap
Dim g As Graphics

Dim delenDoor, delenDoorHO, delenDoorBR As Double
'delenDoor = divide by
'delenDoorHO = divide by height
'delenDoorBR = divide by width

imgOrg = DirectCast(Bitmap.FromFile(myFileName), Bitmap)

'Get the forms' dimensions
delenDoorBR = imgOrg.Width / Me.ClientSize.Width
delenDoorHO = imgOrg.Height / Me.ClientSize.Height
If delenDoorBR > 1 Or delenDoorHO > 1 Then
If delenDoorBR > delenDoorHO Then
delenDoor = delenDoorBR
Else
delenDoor = delenDoorHO
End If

imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / delenDoor),
CInt(CDbl(imgOrg.Height) / delenDoor))
imgShow.SetResolution(imgOrg.HorizontalResolution,
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0,
CInt(CDbl(imgOrg.Width) / delenDoor), CInt(CDbl(imgOrg.Height) /
delenDoor)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
g.Dispose()
Else
imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
imgShow.SetResolution(imgOrg.HorizontalResolution,
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width,
imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, _ GraphicsUnit.Pixel)
g.Dispose()
End If
imgOrg.Dispose()

Me.BackgroundImage = imgShow
Me.Refresh()

Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'pass the image file you want to load
loadimage("c:\2_1024x768.jpg")
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"mcnewsxp" <mc******@mindspring.com> schreef in bericht
news:Ot**************@TK2MSFTNGP10.phx.gbl...
how can i set a back ground image property on an MDI main form to
stretch?


Mar 24 '06 #3

P: n/a
I think it isn't possible in 2003 to strech the backgroundimage when it's
set via the design window

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"mcnewsxp" <mc******@mindspring.com> schreef in bericht
news:#A**************@TK2MSFTNGP12.phx.gbl...
what if the image was placed on the form in the design window?

Me.BackgroundImage ?

"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi again,

in .net 2003 you have to resize the image your self via code, below is an example that resizes the image and keeps the correct proportions, it
shouldn't be to hard to modify the code so the image stretches over the
entire form ignorig the proportions. This in fact would be less code then the sample.

Hope this helps

Greetz, Peter

Private Sub loadimage(ByVal myFileName As String)
Try
Dim imgOrg As Bitmap
Dim imgShow As Bitmap
Dim g As Graphics

Dim delenDoor, delenDoorHO, delenDoorBR As Double
'delenDoor = divide by
'delenDoorHO = divide by height
'delenDoorBR = divide by width

imgOrg = DirectCast(Bitmap.FromFile(myFileName), Bitmap)

'Get the forms' dimensions
delenDoorBR = imgOrg.Width / Me.ClientSize.Width
delenDoorHO = imgOrg.Height / Me.ClientSize.Height
If delenDoorBR > 1 Or delenDoorHO > 1 Then
If delenDoorBR > delenDoorHO Then
delenDoor = delenDoorBR
Else
delenDoor = delenDoorHO
End If

imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / delenDoor), CInt(CDbl(imgOrg.Height) / delenDoor))
imgShow.SetResolution(imgOrg.HorizontalResolution,
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0,
CInt(CDbl(imgOrg.Width) / delenDoor), CInt(CDbl(imgOrg.Height) /
delenDoor)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
g.Dispose()
Else
imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
imgShow.SetResolution(imgOrg.HorizontalResolution,
imgOrg.VerticalResolution)
g = Graphics.FromImage(imgShow)
g.InterpolationMode =
Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width,
imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, _ GraphicsUnit.Pixel)
g.Dispose()
End If
imgOrg.Dispose()

Me.BackgroundImage = imgShow
Me.Refresh()

Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub

Private Sub form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'pass the image file you want to load
loadimage("c:\2_1024x768.jpg")
End Sub

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"mcnewsxp" <mc******@mindspring.com> schreef in bericht
news:Ot**************@TK2MSFTNGP10.phx.gbl...
how can i set a back ground image property on an MDI main form to
stretch?



Mar 27 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.