我相信这个问题有一个简单明了的答案,但是我似乎无法解决它。
我正在尝试使用鼠标悬停事件 mousehover
添加一个 tooltip
。历史上,我一直使用 mousemove
事件,但不幸的是,这意味着 tooltip
将随程序能够执行的速度更新。我只希望在鼠标停留在我的图表上时显示。
问题在于我无法获取 e.Location
属性,因为事件处理程序仅使用 EventArgs
,而不是 MouseEventArgs
。有没有办法可以改变这种情况?或者像 MouseEventArgs mouse = new MouseEventArgs();
这样添加一行代码(我收到一个错误,说需要更多的参数,但我不知道哪些参数)。
感谢任何帮助 :)
private void chSysData_MouseHover(object sender, EventArgs e)
{
//Add tooltip
try
{
int cursorX = Convert.ToInt32(chSysData.ChartAreas[0].AxisX.PixelPositionToValue(e.Location.X));
tipInfo = "System: " + systemVoltage[cursorX].ToString("0.00") + Environment.NewLine + "Current: " + currArray[cursorX].ToString("0.00") + Environment.NewLine;
tooltip.SetToolTip(chSysData, tipInfo);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
Member 'System.Windows.Forms.Cursor.Position.get' cannot be accessed with an instance reference; qualify it with a type name instead
。我以前从未见过。在我试图解决它的时候有什么建议吗? - tmwoodsvar pos = chSysData.PointToClient(System.Windows.Forms.Cursor.Position);
。再次感谢! - tmwoods