Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Converting MouseDown Coordinates to Chart Point Coordinates

Hi,

I want to respond to a user drawn box on an Excel chart. I can get
the X & Y coordinates of the box using the MouseDown or MouseMove
event, but they are in something called ClientCoordinates. I can
develop a formula to convert from ClientCoordinates to those required
to add a Shape to the Chart, but if the zoom is changed this formula
does not hold. Does anyone know how to convert from ClientCoordinates
to points on a chart so that a shape can be drawn by mousing over the
chart, regardless of zoom?

Steve
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Converting MouseDown Coordinates to Chart Point Coordinates

Steve -

This Mouse_Move event gets client X,Y coordinates, finds what's under
that point, and if it's a shape, it puts the Left, Top, Width, and
Height in points into the worksheet.

Private Sub EmbChart_MouseMove _
(ByVal Button As Long, ByVal Shift As Long, _
ByVal X As Long, ByVal Y As Long)

Dim ElementID As Long, Arg1 As Long, Arg2 As Long
Dim myX As Double, myY As Double
Dim myName As String

With EmbChart
.GetChartElement X, Y, ElementID, Arg1, Arg2

If ElementID = xlShape Then
myName = ActiveChart.Shapes(Arg1).Name
ActiveSheet.Range("L2:L5") = WorksheetFunction.Transpose _
(Array(ElementID, Arg1, Arg2, myName))
ActiveSheet.Range("M2:M5") = WorksheetFunction.Transpose _
(Array( _
ActiveChart.Shapes(Arg1).Left, _
ActiveChart.Shapes(Arg1).Top, _
ActiveChart.Shapes(Arg1).Width, _
ActiveChart.Shapes(Arg1).Height))
End If
End With
End Sub

- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______


Steve wrote:

Hi,

I want to respond to a user drawn box on an Excel chart. I can get
the X & Y coordinates of the box using the MouseDown or MouseMove
event, but they are in something called ClientCoordinates. I can
develop a formula to convert from ClientCoordinates to those required
to add a Shape to the Chart, but if the zoom is changed this formula
does not hold. Does anyone know how to convert from ClientCoordinates
to points on a chart so that a shape can be drawn by mousing over the
chart, regardless of zoom?

Steve


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Converting MouseDown Coordinates to Chart Point Coordinates


Thanks for the help. I can make use of that, but it's not quite what I
want to do -- I don't think I was real clear in my initial problem
statement. I want to respond to the user mouse clicks to automatically
build the shape, so that the x,y coordinates of the MouseDown Event set
the anchor for the shape, and the x,y coordinates passed back by the
MouseMove Event resize the shape. I've got it working except if the
Excel zoom factor changes. Then my transformation from mouse x,y to
shape X,Y seems to change in some unpredictable manner. I may be
hallucinating, but the behavior also seems different if not all of the
chart is visible in the window.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default Converting MouseDown Coordinates to Chart Point Coordinates

Steven -

Zoomfactor can mess up your best algorithms. Copy a chart on a 100%
zoomed page, change the zoom to 75%, and paste the chart: it's 75% as
large as the original!

In Excel 97, you get goofy results formatting the plot area size if the
entire chart isn't completely visible in the window. And this means it
can't butt against the top of row 1 or the left of column A. I used to
work around that by scrolling the sheet, nudging the chart slightly,
then unnudging the chart and scrolling back. With screenupdating =
false to reduce nausea.

I was doing a little thing using mouse events to draw a shape on a
chart, and I've crashed Excel twice. So I've got nothing intelligent to
add at this time.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
http://www.geocities.com/jonpeltier/Excel/index.html
_______

steven ritter wrote:

Thanks for the help. I can make use of that, but it's not quite what I
want to do -- I don't think I was real clear in my initial problem
statement. I want to respond to the user mouse clicks to automatically
build the shape, so that the x,y coordinates of the MouseDown Event set
the anchor for the shape, and the x,y coordinates passed back by the
MouseMove Event resize the shape. I've got it working except if the
Excel zoom factor changes. Then my transformation from mouse x,y to
shape X,Y seems to change in some unpredictable manner. I may be
hallucinating, but the behavior also seems different if not all of the
chart is visible in the window.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Lat/Lon coordinates to Decimal Cheese Excel Discussion (Misc queries) 4 June 25th 09 11:12 PM
coordinates of a point bayan Charts and Charting in Excel 3 October 7th 06 01:29 PM
X,Y coordinates on chart lgarcia3 Charts and Charting in Excel 2 February 17th 06 11:46 AM
Analyzing X,Y,Z coordinates of a chart jenlo Excel Discussion (Misc queries) 1 January 31st 05 01:05 PM
finding the coordinates of the maximum point on a graph eastham85 Charts and Charting in Excel 2 January 16th 05 01:34 PM


All times are GMT +1. The time now is 03:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"