Link to home
Start Free TrialLog in
Avatar of jazjef
jazjef

asked on

How do I get the XY coordinates for the center of a label that's located within a VB6 picturebox control?

I have a VB6 baseball game with outfielders and infielders represented by their names on labels on a baseball stadium image within a picturebox control. There's a white shape (ball) that moves toward the outfielders. I want to make the ball stop when it surpasses the XY coordinate of the outfielder label that the ball is traveling toward. The XY coordinate for the very center of a label would work best if I could get those values somehow. How can I do this?

I don't want to use the .top or the .left attributes of the labels to make the ball stop because then one has to always uses straight-oriented ballpark photos/images. If a ballpark image is from an angle, then the ball won't travel the full distance to the label if you use the .top or the .left attributes------which is what it does now.

I have found a number of examples showing how to get XY cursor position of the mouse, but none that show you how to get the XY position of a label relative to the picturebox control on which that label is located.

Many thanks.
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Start with this:
Dim LabelCentreX As Single
Dim LabelCentreY As Single
LabelCentreX = Label1.Left + Label1.Width / 2
LabelCentreY = Label1.Top + Label1.Height / 2

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be closed as follows:

Accepted answer: 500 points for Martin Liss's comment #a40828861

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Avatar of jazjef
jazjef

ASKER

This solution works----I had to learn a lot, and then try to implement it. The learning was easy, but getting it configured was harder.... but I have it working pretty well. Thanks. [I was on vacation---that's why I couldn't respond as quickly]