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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center image coordinate on a form 2

Status
Not open for further replies.

avarga82

Programmer
May 19, 2003
62
US
HELP!

I'm loading a huge (2330 x 2878) image into a picture box on my form. Now, I want to be able to center on any coordinate on that picture. So...for explanation purposes, we have a huge picture of US. I want to be able to center Pittsburgh on the form, or be able to center Houston on the form, etc. The form's AutoScroll is set to true, but can't seem to be able to control them programatically. Any ideas..??






 
As far as I know, you can't control the form's scrollbars programatically.
You'll want to add VScrollBar and HScrollBar controls and write code that updates the positions of the picturebox, VScrollBar, and HScrollBar.

-Stephen Paszt
 
Ok...I've moved on from the scroll bar theory. I can 'center' the picture box on the form using it's Top & Left properties, which is sufficient. What I need to do is do it programatically. So, with the form any size, i need to position the picturebox so that coordinate 1022, 777 (random number), is centered on the form. Any ideas??
 

Try this (pb is a pictureBox):

Code:
Sub CenterToPoint(ByVal pt As Point)
    pb.Left = (Me.ClientSize.Width / 2) - pt.X
    pb.Top = (Me.ClientSize.Height / 2) - pt.Y
End Sub

to use:

Code:
CenterToPoint(New Point(1022, 777))

to center the image (to the center point of the image):

Code:
CenterToPoint(New Point(pb.Width / 2, pb.Height / 2))

-Stephen Paszt
 
And very deserving of a Star me thinks?? [wink]

Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top