Home All Groups Group Topic Archive Search About

set back ground image to stretch

Author
23 Mar 2006 4:42 PM
mcnewsxp
how can i set a back ground image property on an MDI main form to stretch?

Author
24 Mar 2006 7:29 AM
Peter Proost
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)

Show quoteHide quote
"mcnewsxp" <mcour***@mindspring.com> schreef in bericht
news:OtCj4ipTGHA.3976@TK2MSFTNGP10.phx.gbl...
> how can i set a back ground image property on an MDI main form to stretch?
>
>
Author
24 Mar 2006 6:12 PM
mcnewsxp
what if the image was placed on the form in the design window?

Me.BackgroundImage ?

Show quoteHide quote
"Peter Proost" <pproost@nospam.hotmail.com> wrote in message
news:%23t0YhSxTGHA.1868@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" <mcour***@mindspring.com> schreef in bericht
> news:OtCj4ipTGHA.3976@TK2MSFTNGP10.phx.gbl...
>> how can i set a back ground image property on an MDI main form to
>> stretch?
>>
>>
>
>
Author
27 Mar 2006 6:11 AM
Peter Proost
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)

Show quoteHide quote
"mcnewsxp" <mcour***@mindspring.com> schreef in bericht
news:#AWWV62TGHA.4452@TK2MSFTNGP12.phx.gbl...
> what if the image was placed on the form in the design window?
>
>  Me.BackgroundImage ?
>
> "Peter Proost" <pproost@nospam.hotmail.com> wrote in message
> news:%23t0YhSxTGHA.1868@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" <mcour***@mindspring.com> schreef in bericht
> > news:OtCj4ipTGHA.3976@TK2MSFTNGP10.phx.gbl...
> >> how can i set a back ground image property on an MDI main form to
> >> stretch?
> >>
> >>
> >
> >
>
>