set back ground image to stretch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mcnewsxp

    #1

    set back ground image to stretch

    how can i set a back ground image property on an MDI main form to stretch?


  • Peter Proost

    #2
    Re: set back ground image to stretch

    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(Bitm ap.FromFile(myF ileName), Bitmap)

    'Get the forms' dimensions
    delenDoorBR = imgOrg.Width / Me.ClientSize.W idth
    delenDoorHO = imgOrg.Height / Me.ClientSize.H eight


    If delenDoorBR > 1 Or delenDoorHO > 1 Then
    If delenDoorBR > delenDoorHO Then
    delenDoor = delenDoorBR
    Else
    delenDoor = delenDoorHO
    End If

    imgShow = New Bitmap(CInt(CDb l(imgOrg.Width) / delenDoor),
    CInt(CDbl(imgOr g.Height) / delenDoor))
    imgShow.SetReso lution(imgOrg.H orizontalResolu tion,
    imgOrg.Vertical Resolution)
    g = Graphics.FromIm age(imgShow)
    g.Interpolation Mode =
    Drawing2D.Inter polationMode.Hi ghQualityBicubi c
    g.DrawImage(img Org, New Rectangle(0, 0,
    CInt(CDbl(imgOr g.Width) / delenDoor), CInt(CDbl(imgOr g.Height) /
    delenDoor)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pi xel)
    g.Dispose()
    Else
    imgShow = New Bitmap(imgOrg.W idth, imgOrg.Height)
    imgShow.SetReso lution(imgOrg.H orizontalResolu tion,
    imgOrg.Vertical Resolution)
    g = Graphics.FromIm age(imgShow)
    g.Interpolation Mode =
    Drawing2D.Inter polationMode.Hi ghQualityBicubi c
    g.DrawImage(img Org, New Rectangle(0, 0, imgOrg.Width,
    imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, _ GraphicsUnit.Pi xel)
    g.Dispose()
    End If
    imgOrg.Dispose( )

    Me.BackgroundIm age = imgShow
    Me.Refresh()

    Catch ex As Exception
    MsgBox(ex.ToStr ing)
    End Try

    End Sub

    Private Sub form1_Load(ByVa l sender As Object, ByVal e As
    System.EventArg s) 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" <mcourter@minds pring.com> schreef in bericht
    news:OtCj4ipTGH A.3976@TK2MSFTN GP10.phx.gbl...[color=blue]
    > how can i set a back ground image property on an MDI main form to stretch?
    >
    >[/color]


    Comment

    • mcnewsxp

      #3
      Re: set back ground image to stretch

      what if the image was placed on the form in the design window?

      Me.BackgroundIm age ?

      "Peter Proost" <pproost@nospam .hotmail.com> wrote in message
      news:%23t0YhSxT GHA.1868@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > 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(Bitm ap.FromFile(myF ileName), Bitmap)
      >
      > 'Get the forms' dimensions
      > delenDoorBR = imgOrg.Width / Me.ClientSize.W idth
      > delenDoorHO = imgOrg.Height / Me.ClientSize.H eight
      >
      >
      > If delenDoorBR > 1 Or delenDoorHO > 1 Then
      > If delenDoorBR > delenDoorHO Then
      > delenDoor = delenDoorBR
      > Else
      > delenDoor = delenDoorHO
      > End If
      >
      > imgShow = New Bitmap(CInt(CDb l(imgOrg.Width) / delenDoor),
      > CInt(CDbl(imgOr g.Height) / delenDoor))
      > imgShow.SetReso lution(imgOrg.H orizontalResolu tion,
      > imgOrg.Vertical Resolution)
      > g = Graphics.FromIm age(imgShow)
      > g.Interpolation Mode =
      > Drawing2D.Inter polationMode.Hi ghQualityBicubi c
      > g.DrawImage(img Org, New Rectangle(0, 0,
      > CInt(CDbl(imgOr g.Width) / delenDoor), CInt(CDbl(imgOr g.Height) /
      > delenDoor)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pi xel)
      > g.Dispose()
      > Else
      > imgShow = New Bitmap(imgOrg.W idth, imgOrg.Height)
      > imgShow.SetReso lution(imgOrg.H orizontalResolu tion,
      > imgOrg.Vertical Resolution)
      > g = Graphics.FromIm age(imgShow)
      > g.Interpolation Mode =
      > Drawing2D.Inter polationMode.Hi ghQualityBicubi c
      > g.DrawImage(img Org, New Rectangle(0, 0, imgOrg.Width,
      > imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, _ GraphicsUnit.Pi xel)
      > g.Dispose()
      > End If
      > imgOrg.Dispose( )
      >
      > Me.BackgroundIm age = imgShow
      > Me.Refresh()
      >
      > Catch ex As Exception
      > MsgBox(ex.ToStr ing)
      > End Try
      >
      > End Sub
      >
      > Private Sub form1_Load(ByVa l sender As Object, ByVal e As
      > System.EventArg s) 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" <mcourter@minds pring.com> schreef in bericht
      > news:OtCj4ipTGH A.3976@TK2MSFTN GP10.phx.gbl...[color=green]
      >> how can i set a back ground image property on an MDI main form to
      >> stretch?
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Peter Proost

        #4
        Re: set back ground image to stretch

        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" <mcourter@minds pring.com> schreef in bericht
        news:#AWWV62TGH A.4452@TK2MSFTN GP12.phx.gbl...[color=blue]
        > what if the image was placed on the form in the design window?
        >
        > Me.BackgroundIm age ?
        >
        > "Peter Proost" <pproost@nospam .hotmail.com> wrote in message
        > news:%23t0YhSxT GHA.1868@TK2MSF TNGP09.phx.gbl. ..[color=green]
        > > Hi again,
        > >
        > > in .net 2003 you have to resize the image your self via code, below is[/color][/color]
        an[color=blue][color=green]
        > > 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[/color][/color]
        then[color=blue][color=green]
        > > 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(Bitm ap.FromFile(myF ileName), Bitmap)
        > >
        > > 'Get the forms' dimensions
        > > delenDoorBR = imgOrg.Width / Me.ClientSize.W idth
        > > delenDoorHO = imgOrg.Height / Me.ClientSize.H eight
        > >
        > >
        > > If delenDoorBR > 1 Or delenDoorHO > 1 Then
        > > If delenDoorBR > delenDoorHO Then
        > > delenDoor = delenDoorBR
        > > Else
        > > delenDoor = delenDoorHO
        > > End If
        > >
        > > imgShow = New Bitmap(CInt(CDb l(imgOrg.Width) /[/color][/color]
        delenDoor),[color=blue][color=green]
        > > CInt(CDbl(imgOr g.Height) / delenDoor))
        > > imgShow.SetReso lution(imgOrg.H orizontalResolu tion,
        > > imgOrg.Vertical Resolution)
        > > g = Graphics.FromIm age(imgShow)
        > > g.Interpolation Mode =
        > > Drawing2D.Inter polationMode.Hi ghQualityBicubi c
        > > g.DrawImage(img Org, New Rectangle(0, 0,
        > > CInt(CDbl(imgOr g.Width) / delenDoor), CInt(CDbl(imgOr g.Height) /
        > > delenDoor)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pi xel)
        > > g.Dispose()
        > > Else
        > > imgShow = New Bitmap(imgOrg.W idth, imgOrg.Height)
        > > imgShow.SetReso lution(imgOrg.H orizontalResolu tion,
        > > imgOrg.Vertical Resolution)
        > > g = Graphics.FromIm age(imgShow)
        > > g.Interpolation Mode =
        > > Drawing2D.Inter polationMode.Hi ghQualityBicubi c
        > > g.DrawImage(img Org, New Rectangle(0, 0, imgOrg.Width,
        > > imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, _ GraphicsUnit.Pi xel)
        > > g.Dispose()
        > > End If
        > > imgOrg.Dispose( )
        > >
        > > Me.BackgroundIm age = imgShow
        > > Me.Refresh()
        > >
        > > Catch ex As Exception
        > > MsgBox(ex.ToStr ing)
        > > End Try
        > >
        > > End Sub
        > >
        > > Private Sub form1_Load(ByVa l sender As Object, ByVal e As
        > > System.EventArg s) 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[/color][/color]
        produce[color=blue][color=green]
        > > bigger and better idiots. So far, the Universe is winning. (Rich Cook)
        > >
        > > "mcnewsxp" <mcourter@minds pring.com> schreef in bericht
        > > news:OtCj4ipTGH A.3976@TK2MSFTN GP10.phx.gbl...[color=darkred]
        > >> how can i set a back ground image property on an MDI main form to
        > >> stretch?
        > >>
        > >>[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...