Decent image control

B

Bob

Hi there,

I need to show an image centered on a form. That's easy,
use a Picturebox... problem is the images may be
different sizes, and I need to resize to show the image
with the correct aspect ratio (ie: height vs width)...
sometimes the image will be too big to fit on the form so
then I'd like scrollbars... I need like a "shrink/stretch
to fit" method which understands the aspect ratio bit....

Is it me or is the picturebox control pretty useless...?

Can anybody suggest a way of achieving what I want with
standard .Net controls... or am I going to have to
subclass the picturebox (or make my own version)...?

Any help appreciated...

Cheers
 
J

Jason Dorie

Could you put the PictureBox control inside a Panel control? The panel
should allow you to scroll when the controls inside it are larger than its
client area.

Jason Dorie
 
H

Herfried K. Wagner [MVP]

* "Bob said:
I need to show an image centered on a form. That's easy,
use a Picturebox... problem is the images may be
different sizes, and I need to resize to show the image
with the correct aspect ratio (ie: height vs width)...
sometimes the image will be too big to fit on the form so
then I'd like scrollbars... I need like a "shrink/stretch
to fit" method which understands the aspect ratio bit....

Is it me or is the picturebox control pretty useless...?

Can anybody suggest a way of achieving what I want with
standard .Net controls... or am I going to have to
subclass the picturebox (or make my own version)...?

You can add the picturebox control to a panel control with 'AutoScroll'
= 'True'. If the pixturebox gets larger than the panel, scrollbars will
be showed. The picturebox provides a 'SizeMode' property which allows
you to specify the size mode.
 
B

Bob Powell [MVP]

The GDI+ FAQ has an article on how to display an image in its original
aspect ratio centered on a form or control. It would be easy to adapt this
to a control that would do what you need.

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top