Программирование на Visual Basic, главный форум. Обсуждение тем программирования на VB 1—6.
Даже если вы плохо разбираетесь в VB и программировании вообще — тут вам помогут. В разумных пределах, конечно.
Правила форума
Темы, в которых будет сначала написано «что нужно сделать», а затем просьба «помогите», будут
закрыты.
Читайте
требования к создаваемым темам.
-
KPEATOP
-
- Бывалый

-
-
- Сообщения: 291
- Зарегистрирован: 02.12.2002 (Пн) 16:33
- Откуда: Russia
KPEATOP » 08.05.2007 (Вт) 9:54
Имеется событие MSChart1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
здесь X и Y координаты мыши на элементе MSChart1 в твипах.
Как можно перевести эти координаты в координаты графика MSChart1
(т.е. в координаты шкалы X и Y графика MSChart1), если конечно это вообще возможно. Думаю, я понятно объяснил. Очень долго ломаю над этим вопросом голову.
Большое спасибо тем, кто ответит.
Вечность пахнет нефтью
-
GSerg
-
- Шаман

-
-
- Сообщения: 14286
- Зарегистрирован: 14.12.2002 (Сб) 5:25
- Откуда: Магадан
GSerg » 09.05.2007 (Ср) 13:50
Поиски нужно сделать бинарными (мне было лень). Иначе небыстро.
- Код: Выделить всё
Private Function GetAxisCoords(ByVal c As MSChart, ByVal AxisType As VtChAxisId, ByRef outX0 As Long, ByRef outX1 As Long, ByRef outY0 As Long, ByRef outY1 As Long) As Boolean
Dim x As Long, y As Long
Dim curPart As Integer, curPartIndex As Integer
Select Case AxisType
Case VtChAxisIdX
x = Abs(c.Plot.LocationRect.Min.x - c.Plot.LocationRect.Max.x) / 2
For y = c.Plot.LocationRect.Max.y To c.Plot.LocationRect.Min.y Step -1
c.TwipsToChartPart x, y, curPart, curPartIndex, 0, 0, 0
If curPart = VtChPartTypeAxis Then
If curPartIndex = VtChAxisIdX Then
outY0 = y
outY1 = y
GetAxisCoords = True
Exit For
End If
End If
Next
'Эти два поиска нужно сделать бинарными; лень.
If GetAxisCoords Then
For outX0 = c.Plot.LocationRect.Min.x To x
c.TwipsToChartPart outX0, outY0, curPart, curPartIndex, 0, 0, 0
If curPart = VtChPartTypeAxis Then
If curPartIndex = VtChAxisIdX Then
Exit For
End If
End If
Next
If outX0 > x Then
GetAxisCoords = False
Exit Function
End If
For outX1 = c.Plot.LocationRect.Max.x To x Step -1
c.TwipsToChartPart outX1, outY0, curPart, curPartIndex, 0, 0, 0
If curPart = VtChPartTypeAxis Then
If curPartIndex = VtChAxisIdX Then
Exit For
End If
End If
Next
If outX1 < x Then
GetAxisCoords = False
Exit Function
End If
End If
Case VtChAxisIdY, VtChAxisIdY2
y = Abs(c.Plot.LocationRect.Min.y - c.Plot.LocationRect.Max.y) / 2
For x = IIf(AxisType = VtChAxisIdY, c.Plot.LocationRect.Min.x, c.Plot.LocationRect.Max.x) To IIf(AxisType = VtChAxisIdY, c.Plot.LocationRect.Max.x, c.Plot.LocationRect.Min.x) Step IIf(AxisType = VtChAxisIdY, 1, -1)
c.TwipsToChartPart x, y, curPart, curPartIndex, 0, 0, 0
If curPart = VtChPartTypeAxis Then
If curPartIndex = AxisType Then
outX0 = x
outX1 = x
GetAxisCoords = True
Exit For
End If
End If
Next
'Эти два поиска нужно сделать бинарными; лень.
If GetAxisCoords Then
For outY0 = c.Plot.LocationRect.Min.y To y
c.TwipsToChartPart outX0, outY0, curPart, curPartIndex, 0, 0, 0
If curPart = VtChPartTypeAxis Then
If curPartIndex = AxisType Then
Exit For
End If
End If
Next
If outY0 > y Then
GetAxisCoords = False
Exit Function
End If
For outY1 = c.Plot.LocationRect.Max.y To y Step -1
c.TwipsToChartPart outX0, outY1, curPart, curPartIndex, 0, 0, 0
If curPart = VtChPartTypeAxis Then
If curPartIndex = AxisType Then
Exit For
End If
End If
Next
If outY1 < y Then
GetAxisCoords = False
Exit Function
End If
End If
Case Else
Err.Raise 5, , "Unsupported Axis type"
End Select
End Function
Как только вы переберёте все варианты решения и не найдёте нужного, тут же обнаружится решение, простое и очевидное для всех, кроме вас
Вернуться в Visual Basic 1–6
Кто сейчас на конференции
Сейчас этот форум просматривают: AhrefsBot, Google-бот, SemrushBot и гости: 7