PictureBox with scroll bar control

M

midicad2001

I have been researching this issue and have come across a number of
solutions apparently written for VB5 or 6 and don't work under .NET,
yes folks that is progress!

Someone in this ng suggested just drop your picturebox into a panel
with autoscroll=TRUE.

I am wondering if this will work for my desired application - see
details.

I have a fixed size dialog with a fixed size window for showing
graphics. This means that my form will never get resized so as to
impinge on the picturebox (this is apparently how some of the demos I
tried worked).

For starters I would like to fit the loaded images horizontally or
vertically so as to only have 1 scrollbar at a time. So I would scale
my imagefromfile to match the panel size on one axis. If the
picturebox thus sized turns out to be larger than the panel it's
sitting in, then I presume scrollbars are shown and scrolling enabled?

I've been spending way too much time on this - thought it would be
simple, and maybe it is!

Thanks,

Gary
 
H

Herfried K. Wagner [MVP]

Hi,

I have a fixed size dialog with a fixed size window for showing
graphics. This means that my form will never get resized so as to
impinge on the picturebox (this is apparently how some of the demos I
tried worked).

For starters I would like to fit the loaded images horizontally or
vertically so as to only have 1 scrollbar at a time. So I would scale
my imagefromfile to match the panel size on one axis.

Check out the picturebox' 'SizeMode' property.
If the picturebox thus sized turns out to be larger than the panel it's
sitting in, then I presume scrollbars are shown and scrolling enabled?

Yes, that should work.
 
M

midicad2001

Herfried said:
Check out the picturebox' 'SizeMode' property.

OK, I would use the (I think) 3rd option which just keeps the image at
a fixed size to be determined by the program (e.g. the Image width
would be scaled to match the panel's width, then the image could scroll
up and down - if Portrait oriented)

How do I accomplish this scaling? Do I need an intermediate image
object?

i.e. load image from file to 1 image then scale that image onto the
picturebox within the panel? Or can I do it directly as I load the
image?

As you can tell I really don't know much about this.

Thanks,

Gary
 
H

Herfried K. Wagner [MVP]

OK, I would use the (I think) 3rd option which just keeps the image at
a fixed size to be determined by the program (e.g. the Image width
would be scaled to match the panel's width, then the image could scroll
up and down - if Portrait oriented)

How do I accomplish this scaling? Do I need an intermediate image
object?

i.e. load image from file to 1 image then scale that image onto the
picturebox within the panel? Or can I do it directly as I load the
image?

Add a panel control to the form and a picturebox control to the panel
control:

\\\
Me.Panel1.AutoScroll = True
With Me.PictureBox1
.SizeMode = PictureBoxSizeMode.StretchImage
Dim img As Image = Image.FromFile("C:\WINDOWS\winnt.bmp")
.Height = img.Height * Me.Panel1.ClientSize.Width / img.Width
.Width = Me.Panel1.ClientSize.Width
If Me.Panel1.ClientSize.Height > img.Height Then
.Width -= SystemInformation.VerticalScrollBarWidth
End If
.Image = img
End With
///
 
D

Drily Lit Raga

Herfried said:
Add a panel control to the form and a picturebox control to the panel
control:

\\\
Me.Panel1.AutoScroll = True
With Me.PictureBox1
.SizeMode = PictureBoxSizeMode.StretchImage
Dim img As Image = Image.FromFile("C:\WINDOWS\winnt.bmp")
.Height = img.Height * Me.Panel1.ClientSize.Width / img.Width
.Width = Me.Panel1.ClientSize.Width
If Me.Panel1.ClientSize.Height > img.Height Then
.Width -= SystemInformation.VerticalScrollBarWidth
End If
.Image = img
End With

Thank you very much! By changing ">" to "<" on the comparison line I
got it to work perfectly!
 

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