我正在使用 Windows 窗体在 C# 中创建 GUI。为了以图形表示形式查看数据,我使用了 .Net v3 的许可 TeeChart。我想在 TeeChart 中实现鼠标点击事件。我有 VB6 代码,因为 GUI 之前是在 VB6 中创建的。我已将该 VB6 代码转换为 C#,但仍有一些问题。我想在 TeeChart 上创建鼠标点击弹出窗口。下面的代码显示了在 teechart 上创建鼠标单击弹出窗口的 Vb6 代码。
Private Sub TChart1_OnMouseUp(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal x As Long, ByVal y As Long)
If Not m_objTransfer Is Nothing Then
If chkGraphVolume.value = vbChecked And Button = mbRight Then
'MsgBox TChart1.Series(0).XValueToText(x)
'MsgBox TChart1.Series(0).XValueToText(TChart1.Series(0).XScreenToValue(x))
'MsgBox TChart1.Series(0).XScreenToValue(x)
m_dblTempVolFromTo = Round(TChart1.Series(0).XValueToText(TChart1.Series(0).XScreenToValue(x)))
mnuPopupChartFrom.Caption = "From " & m_dblTempVolFromTo & " cc"
mnuPopupChartTo.Caption = "To " & m_dblTempVolFromTo & " cc"
PopupMenu mnuPopupChart
ElseIf chkGraphVolume.value = vbUnchecked And Button = mbRight Then
Debug.Print CDate(TChart1.Series(0).XScreenToValue(x))
mnuPopupChartFrom.Caption = "From " & CDate(TChart1.Series(0).XScreenToValue(x))
mnuPopupChartTo.Caption = "To " & CDate(TChart1.Series(0).XScreenToValue(x))
m_dtTempTimeFromTo = CDate(TChart1.Series(0).XScreenToValue(x))
PopupMenu mnuPopupChart
End If
End If
Debug.Print "From " TChart1.Series(0).XValueToText(TChart1.Series(0).XScreenToValue(x)) & " cc
End Sub
我已将上述代码转换为 C#
private void TChart1_OnMouseUp(TeeChart.EMouseButton Button, TeeChart.EShiftState Shift, long x, long y) {
if (!(m_objTransfer == null)) {
if (((chkGraphVolume.value == vbChecked)
&& (Button == mbRight))) {
// MsgBox TChart1.Series(0).XValueToText(x)
// MsgBox TChart1.Series(0).XValueToText(TChart1.Series(0).XScreenToValue(x))
// MsgBox TChart1.Series(0).XScreenToValue(x)
m_dblTempVolFromTo = Round(TChart1.Series(0).XValueToText(TChart1.Series(0).XScreenToValue(x)));
mnuPopupChartFrom.Caption = ("From "
+ (m_dblTempVolFromTo + " cc"));
mnuPopupChartTo.Caption = ("To "
+ (m_dblTempVolFromTo + " cc"));
PopupMenu;
mnuPopupChart;
}
else if (((chkGraphVolume.value == vbUnchecked)
&& (Button == mbRight))) {
Debug.Print;
DateTime.Parse(TChart1.Series(0).XScreenToValue(x));
mnuPopupChartFrom.Caption = ("From " + DateTime.Parse(TChart1.Series(0).XScreenToValue(x)));
mnuPopupChartTo.Caption = ("To " + DateTime.Parse(TChart1.Series(0).XScreenToValue(x)));
m_dtTempTimeFromTo = DateTime.Parse(TChart1.Series(0).XScreenToValue(x));
PopupMenu;
mnuPopupChart;
}
}
Debug.Print;
("From " + (TChart1.Series(0).XValueToText(TChart1.Series(0).XScreenToValue(x)) + " cc"));
}
但我无法使用上面的代码在 TeeChart 上创建弹出窗口。我想在鼠标单击时使用 x 轴位置创建弹出菜单。所以请帮我解决这个问题。
提前致谢。