 |
 |

07-30-2012, 09:14 PM
|
|
Junior Contributor
|
|
Join Date: Aug 2001
Posts: 235
|
|
Picturebox click conversion.
|
I have a picturebox that is sized to my form that has a graticule scale drawn in it. The scale runs from 7300 -7000 you can see this in the image I have attached. I am trying to make a conversion from where the user click say y=199 and convert that to a number that is represented by a number on the scale. Below is the code I have been toying with but have not come up with the correct calculation to give the right number. if the user clicks on 7150(green line), y=197. I am hoping someone can show me the right formula that I am missing.
Code:
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim temp As Double
Dim tscale As Double
MsgBox " You clicked at: " & CStr(x) & " " & CStr(y)
tscale = ((Picture1.ScaleHeight - 20) / (maxF - minF))
temp = maxF - (y * tscale)
Debug.Print temp
End Sub
Thanks
Rick
|
|

07-31-2012, 06:26 AM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
You're setting tscale to pixels per unit (pixels/units).
To convert pixels to units you want tscale to be units per pixel (units/pixels).
Of course, you could have the picturebox do the work.
Picturebox1.ScaleTop = 7300
Picturebox1.ScaleHeight = -320 'note negative because scale goes down vertically
Now when you click on the picturebox, Y will be your scale value.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|

07-31-2012, 11:50 AM
|
|
Junior Contributor
|
|
Join Date: Aug 2001
Posts: 235
|
|
|
I had tried using the ScaleTop and height but when the other number series are used I would need to re-scale for each set and in some of the sets the scale got to small to hold the data that gets printed along with the number scale.
If using the scale routine
tscale = ((maxBandMapFreq - minBandMapFreq) / Picture1.ScaleHeight - 20)
What would the formula need to be to make the conversion. I'm running into an issue as the number is not even close to where the click took place.
|
|

07-31-2012, 01:17 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
Is that line what you used,
tscale = ((maxBandMapFreq - minBandMapFreq) / Picture1.ScaleHeight - 20)
try
tscale = (maxBandMapFreq - minBandMapFreq) / (Picture1.ScaleHeight - 20)
And I don't understand the problem with scaling the coordinate system of the picturebox.
It usally makes it easier to plot the data if the picturebox coordinate system is scaled to fit the range of the data to be plotted (you don't need to scale the data to fit your plot, just plot it directly).
But, whatever works for you.
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|

07-31-2012, 03:05 PM
|
|
Junior Contributor
|
|
Join Date: Aug 2001
Posts: 235
|
|
|
Funny how extra parenthesis cause an error. Everything is working correctly now..
Thanks..
|
|

07-31-2012, 03:21 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
|
Not some extra, just misplaced.
Your divide probably ends up with tscale being a small number, say between 1 and 2 (or 3).
Because you had the -20 outside the parenthesis, you subtracted 20 from the small number, so ended up with something like -18 to -20, which then cause your scale to be in the neighborhood of 10x what it should have been (and in the wrong direction).
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|