想寫一個在日曆上的實時提醒功能,即在鼠標滑動到某一天時提示相應信息。
MonthCalendar上監視MouseMove事件
開始遇到的問題是實時刷新時會使界面刷新變慢,即MouseMove事件會連續觸發,至今不明原理。。。(可能是因爲ToolTip的刷新會觸發鼠標時間吧。。。)
修改爲如下判斷鼠標座標後可正常使用。
private void monthCalendar1_MouseMove123(object sender, MouseEventArgs e)
{
if (p == Cursor.Position)
{
return;
}
else
{
p = new Point(Cursor.Position.X, Cursor.Position.Y);
}
MonthCalendar.HitTestInfo info = this.monthCalendar1.HitTest(e.Location);
string s = tp.GetToolTip(this.monthCalendar1);
//if (s.Equals(info.Time.ToString()))
//{
//tp.Show(info.Time.ToString(), this.monthCalendar1, new Point(e.X, e.Y));
//return;
// }
//else
{
tp.SetToolTip(this.monthCalendar1, info.Time.ToString());
}
}