Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zoom in to picture box

Status
Not open for further replies.

Appollo14

Technical User
Sep 4, 2003
182
GB
Hi all,

I have a picture box displaying an image and I have a context menu with a zoom option. When i put the two together i get a picture box that allows you to zoom into the image. The problem that i have is that it only zooms intio one point. I want to be able to set the focus of the zoom to be the mouse position when the right click is activated.
I can get the mouse position, how do i then tell the zoom to use these co ordinates?

here is my code.

Dim MouseLoc As Point
MouseLoc = bxImageView.PointToClient(Cursor.Position)

bxImageView.SizeMode = PictureBoxSizeMode.StretchImage
bxImageView.Width = CInt(bxImageView.Width * 1.25) '
bxImageView.Height = CInt(bxImageView.Height * 1.25) '

Many thanks,
Noel.
 
Hi,

I'm not a picturebox guru at all, but -excuse me if i'm wrong-
i think you'd better build a custom control to achieve this task. Create a new custom control, place a picturebox on it. The picture box's minimum size should be at least the same as the custom control's size. As you zoom in or out, enlarge or reduce the picturebox's size to simulate the zoom effect.

To have it zoom where you've clicked, simply make the picturebox moved around the custom control's canvas to match the mouse clicked point.


I hope it's clear enough.
 
Mastakilla,

I am not sure if you are right.
Anyway, if you want to build a new picture box control, then the best is to extend it by inheriting from it, and not create a user control and drop a pic control only.

Appollo14, what version of VB are you using ?
 
Hi both,

thanks for the replies. I'm hoping that i can do this without creating a custom control (mainly cos i haven't got a clue where to start!).

the version of VB is 2003.

Thanks,
Noel.
 
A really cheap and easy way to do this, based kind of on Masta's idea.

Create a new control (right click on solution, add->new user control)

Add a picture box to the control.

either declare the picture box as public on the control, or create public properties/methods on the control to set the image in the picture box.

Set the picture box to stretch, and set the picturebox size to the size of the control, and hit the anchor left, right, top, and bottom.

Add a .ZoomIn and .ZoomOut method to the control. In these methods either increase, or decrease the width of the picture box. Make sure you split the difference to keep the image centered. To zoom in, Add 2 to the height and width, and subtract 1 from the left and top. and the opposite for zooming out. Make sure to watch the picture box's original dimensions so that you don't zoom out all the way with the picture off center.

Changing the center point of the image would be as simple as moving the top and left of the picture box. Again, watch the original dimensions so that you don't wind up with a gray area.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thanks guys,

I'll let you know how i get on.

Regards,
Noel.
 
Hi,

In the end i ended up putting the picture box into a panel and using the following code;

Private Sub MnuZoomIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MnuZoomIn.Click
Dim MouseLoc As Point
MouseLoc = bxImageView.PointToClient(Cursor.Position)
Dim intX As Integer = 0
Dim intY As Integer = 0
Dim intOffX As Integer = 0
Dim intOffY As Integer = 0
Dim SCALEMODE As Single = 1.25

intOffX = CInt((bxImageView.Width / 2) - MouseLoc.X) * SCALEMODE
intOffY = CInt((bxImageView.Height / 2) - MouseLoc.Y) * SCALEMODE

bxImageView.SizeMode = PictureBoxSizeMode.StretchImage
bxImageView.Width = bxImageView.Width * SCALEMODE
bxImageView.Height = bxImageView.Height * SCALEMODE

intX = CInt((Panel1.Width - bxImageView.Width) / 2) + intOffX
intY = CInt((Panel1.Height - bxImageView.Height) / 2) + intOffY

bxImageView.Left = intX
bxImageView.Top = intY

End Sub



seems to work a treat.

Thanks for you help.
Noel.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top