473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Resizing a picturebox using scroll bars

9
Hi there.

Im currently trying to design a project, that loads local images using a dialog box, puts them in a picture box, and changes the height and width, based on the values of scroll bars. The code that calls the loaded image to the picture box is

picBox.Image = Image.FromFile(.FileName)

Im just stuck on where to go from here!

This is just a small part of the project, ive done the rest, but im just stuck on this particular part, and i cant figure it out.
Does anyone have any ideas/links to code that will help me do this?

TIA

Sam
Nov 2 '07 #1
7 5362
balabaster
797 Expert 512MB
Hi there.

Im currently trying to design a project, that loads local images using a dialog box, puts them in a picture box, and changes the height and width, based on the values of scroll bars. The code that calls the loaded image to the picture box is

picBox.Image = Image.FromFile(.FileName)

Im just stuck on where to go from here!

This is just a small part of the project, ive done the rest, but im just stuck on this particular part, and i cant figure it out.
Does anyone have any ideas/links to code that will help me do this?

TIA

Sam
Well I'm going to assume that you already know how to programatically change the size of your picture box by setting it's height and width properties...and the picture size within the picture box using the SizeMode property to set how the picture is sized within the image box...so it's really just a case of finding a control that will allow you to graphically scroll up and down to change the size of the picture box control...

So dump an HScrollbar (or a VScrollbar) onto your form and size it accordingly...as you drag this in realtime, the value will change. You'll obviously need one for height and one for width....so maybe an HScrollbar to set the width and a VScrollbar to set the height.

In the scrollbar scroll events you would set: PictureBox1.Width = e.NewValue or PictureBox1.Height = e.NewValue (depending on which scrollbar you're handling the event for).

Hope that helps
Nov 2 '07 #2
dablyz
9
Hi,

Thanks very much for your reply, it did set some wheels in motion!

However, i have set up the scroll bars to adjust height and width respectively - but when the image is loaded into the box by the user, the scroll bars dont seem to adjust the box size at all, i just get a flickering over the image as i move the values along. It seems almost as if i havent set a property right, but im sure i have!

Also, if i can, one further question - when the image gets resized by picturebox - does the actual jpeg get resized, or does it just scale down to fit? ideally, i have to enable my user to resize the image at runtime, and then have the new dimensions displayed in a labe. (although, i dont need to be able to save the resized image, just show it)

Heres hopeing you can help me again!

Thanks

Sam
Nov 3 '07 #3
balabaster
797 Expert 512MB
Hi,

Thanks very much for your reply, it did set some wheels in motion!

However, i have set up the scroll bars to adjust height and width respectively - but when the image is loaded into the box by the user, the scroll bars dont seem to adjust the box size at all, i just get a flickering over the image as i move the values along. It seems almost as if i havent set a property right, but im sure i have!

Also, if i can, one further question - when the image gets resized by picturebox - does the actual jpeg get resized, or does it just scale down to fit? ideally, i have to enable my user to resize the image at runtime, and then have the new dimensions displayed in a labe. (although, i dont need to be able to save the resized image, just show it)

Heres hopeing you can help me again!

Thanks

Sam
Are you using the right event? I created a demo form with a picture box and a vertical scrollbar. On double clicking the scrollbar the stub for the scroll event will be created...enter the code as follows:
VB
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
  3. PictureBox1.Height = e.NewValue
  4. End Sub
Obviously you need to set the maximum values and the minimum values on your scrollbar to the max/min sizes you want your picture box to be. You would need to follow the same procedure for the width.

Hope that helps.
Nov 4 '07 #4
dablyz
9
Are you using the right event? I created a demo form with a picture box and a vertical scrollbar. On double clicking the scrollbar the stub for the scroll event will be created...enter the code as follows:
VB
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
  3. PictureBox1.Height = e.NewValue
  4. End Sub
Obviously you need to set the maximum values and the minimum values on your scrollbar to the max/min sizes you want your picture box to be. You would need to follow the same procedure for the width.

Hope that helps.
Hi

Looking at it, that did help, as before i had forgotten to adjust the max size of my scroll bars - which seems a bit obvious now!

one more last quick question, lol, if it isnt too much...

With picture boxes, is there any way i can call the current size (that has baan adjusted by the user) to a label? This needs to be done to show the user what size their image is - i was planning to do this in pixels. As i have no padding on my textbox, this would just be the actual box size, wouldnt it? Do you know of the code to do this, i have tried to figure it out, but im getting no where!

Thanks once more for your help, it has been invaluable! :D

Sam
Nov 4 '07 #5
balabaster
797 Expert 512MB
Hi

Looking at it, that did help, as before i had forgotten to adjust the max size of my scroll bars - which seems a bit obvious now!

one more last quick question, lol, if it isnt too much...

With picture boxes, is there any way i can call the current size (that has baan adjusted by the user) to a label? This needs to be done to show the user what size their image is - i was planning to do this in pixels. As i have no padding on my textbox, this would just be the actual box size, wouldnt it? Do you know of the code to do this, i have tried to figure it out, but im getting no where!

Thanks once more for your help, it has been invaluable! :D

Sam
Use the following code in either your picture box resize event or sizechanged event.
VB
Expand|Select|Wrap|Line Numbers
  1. SizeTextLabel.Text = CType(sender, PictureBox).Size.ToString
If you need the heights and widths separately (i.e. to apply your own formatting) you can get Size.Width and Size.Height instead of Size.ToString. But I'm lazy so the example only demonstrates the ToString method.
Nov 4 '07 #6
dablyz
9
Use the following code in either your picture box resize event or sizechanged event.
VB
Expand|Select|Wrap|Line Numbers
  1. SizeTextLabel.Text = CType(sender, PictureBox).Size.ToString
If you need the heights and widths separately (i.e. to apply your own formatting) you can get Size.Width and Size.Height instead of Size.ToString. But I'm lazy so the example only demonstrates the ToString method.

That worked a treat mate, thank you ever so much! :D

Sam
Nov 4 '07 #7
balabaster
797 Expert 512MB
That worked a treat mate, thank you ever so much! :D

Sam
No problem, glad I could help.
Nov 4 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Arlie Rahn | last post by:
I would like to ad a custom scroll bar control to my app that has a customizable and "flat" look to it (not the normal VB look). Does anyone have any ideas on where to find a good one?
1
by: James Dean | last post by:
I am drawing in a picturebox and am having some problems. I display outputted images in the picturebox. If the image is too big for the client area then i have scrollbars. The problem is that once...
2
by: active | last post by:
Problem: The PictureBox display appears to have the image cut off. I.e., the image bottom does not display although the PictureBox has room for it. It occurred to me that what was displayed was...
1
by: Chris Morse | last post by:
I'm trying to figure out how to get Panel to autoscroll a picturebox that changes size. Initially, the picture box is the same size as the panel, but when I add a "zoom" function that doubles the...
0
by: Eric | last post by:
I have a TableLayout that I'm having problems with. I am placing controls in it that have scroll bars. When I put enough of them on the control to make the TableLayout's scroll bars appear the...
4
by: Thiru .Net | last post by:
hi wagner, i have a doubt in panel control in windows application. i have a panel control wherein i have put a picturebox control. i show picture into picturbox control. now i need to zoom in...
0
by: Shane | last post by:
We use non-standard buttons in our app (Ok, Cancel, ...) The MsgBox uses the standard buttons, which looks inconsistent. I need to make a MsgBox replacement. I could use a text box for the...
1
by: David_from_Chicago | last post by:
I am developing an application in Access 2000 (A2K) which has multiple forms and subforms. Until now, all subforms displayed scroll bars properly (according to the subform's property setting). ...
1
by: bwilde | last post by:
Hello, Here's what I'd like to have in a form that I'm creating: A picture box that contains an image that is significantly larger than the box. I'd like for there to be scroll bars, but also to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.