Re: Resize panel image and maintain aspect ratio
From: Peter Proost (pproost_at_nospam.hotmail.com)
Date: 11/02/04
- Next message: Just Me: "Re: Where is the image for the close (X) icom in the window upper right NC corner"
- Previous message: balmerch: "Re: Host mappoint control in vb.net"
- In reply to: Cor Ligthert: "Re: Resize panel image and maintain aspect ratio"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 2 Nov 2004 15:59:56 +0100
Hi,
maybe this can help you, place a panel on a form and then two picturboxes in
the panel,
send the second picturebox to the back. For both pictureboxes chose dock =
fill and for
the panel anchor the top, bottom,left and right. set an image in the image
property of the second
picturebox, copy paste the code below and run the app and resize the form to
see what happens.
Don't mind about the comments in the code, they're in dutch. I know it's not
everything you asked, but it can be a start
hth Peter
<<<<<code>>>>>>
Private bmp As Bitmap
Private ptbBreedte, ptbHoogte As Integer
Private imgBr, imgHo As Integer
Private schaalH, schaalB, schaal As Double
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) _ Handles MyBase.Resize
Try
ptbBreedte = PictureBox1.Width
ptbHoogte = PictureBox1.Height
imgBr = PictureBox2.Image.Width
imgHo = PictureBox2.Image.Height
schaalH = ptbHoogte / imgHo
schaalB = ptbBreedte / imgBr
'schalen gebaseerd op wie de grootste aanpassing moet doen, de hoogte
'of de breedte, in dit geval kan de schaal niet gebaseerd worden op de
'breedte en hoogte van de image omdat de picturebox geresized kan
worden
if schaalH > schaalB Then
schaal = ptbBreedte / imgBr
Else
schaal = ptbHoogte / imgHo
End If
bmp = New Bitmap(Panel1.Width, Panel1.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
g.Clear(Color.White)
g.DrawImage(PictureBox2.Image, New Rectangle(5, 5, CInt(imgBr *
schaal) - 10, _ CInt(imgHo * schaal) - 10), 0, 0, PictureBox2.Image.Width,
PictureBox2.Image.Height, GraphicsUnit.Pixel)
PictureBox1.Image = bmp
g.Dispose()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
<<<<<<<<code>>>>>>>>
"Cor Ligthert" <notmyfirstname@planet.nl> wrote in message
news:eguvpzNwEHA.3808@TK2MSFTNGP15.phx.gbl...
> Carl,
>
> For that you need the GDI+ classes with what are all your questions in my
> opinion completly possible, however no easy stuff and therefore are
samples
> almost very special.
>
> http://msdn.microsoft.com/vbasic/atthemovies/howto/default.aspx
>
> I hope this helps?
>
> Cor
>
>
> "Carl Gilbert" <cnl@newsgroup.nospam>
>
> >
> > I am looking for either a component or technique to allow me to do the
> > following:
> >
> > * Provide a panel with a background image
> > * Resize the image to best fit the panel to maintain aspect ratio
> > * Provide white (or other color) borders at the sides or the top/bottom
> >
> > The last point would be used to allow users to resize the panel to any
> > ratio
> > whilst maintaining the images ratio.
> >
> > Regards, Carl Gilbert
> >
>
>
- Next message: Just Me: "Re: Where is the image for the close (X) icom in the window upper right NC corner"
- Previous message: balmerch: "Re: Host mappoint control in vb.net"
- In reply to: Cor Ligthert: "Re: Resize panel image and maintain aspect ratio"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|