View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier[_4_] Jon Peltier[_4_] is offline
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