Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Picturebox click conversion.


Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2012, 09:14 PM
n2amg n2amg is offline
Junior Contributor
 
Join Date: Aug 2001
Posts: 235
Default 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
Attached Images
File Type: jpg Clipboard01.jpg (10.7 KB, 7 views)
Reply With Quote
  #2  
Old 07-31-2012, 06:26 AM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

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.
Reply With Quote
  #3  
Old 07-31-2012, 11:50 AM
n2amg n2amg is offline
Junior Contributor
 
Join Date: Aug 2001
Posts: 235
Default

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.
Reply With Quote
  #4  
Old 07-31-2012, 01:17 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

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.
Reply With Quote
  #5  
Old 07-31-2012, 03:05 PM
n2amg n2amg is offline
Junior Contributor
 
Join Date: Aug 2001
Posts: 235
Default

Funny how extra parenthesis cause an error. Everything is working correctly now..
Thanks..
Reply With Quote
  #6  
Old 07-31-2012, 03:21 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->