private IAppointment CheckForAppointment(MouseEventArgs e) { bool matchFound = false; IAppointment appointment = null; if (e.X < ApptOffset || e.X > panelDailyView.ClientRectangle.Size.Width - vScrollBar.Width - ApptOffset) { // The X co-ordinate is not inside an appointment, so simply exit return(null); } // Determine the row corresponding to the mouse position int row = e.Y / PanelRowHeight + vScrollBar.Value; // Look through todays appointments to see if we // are positioned on any of them IEnumerator <IAppointment> enumerator = _TodaysAppointments.GetEnumerator(); while (enumerator.MoveNext() && !matchFound) { int apptRow = Utility.ConvertTimeToRow(enumerator.Current.Start); int apptLength = Utility.ConvertLengthToRows(enumerator.Current.Length); if (row >= apptRow && row <= apptRow + apptLength - 1) { matchFound = true; appointment = enumerator.Current; } } return(appointment); }
//This was slightly modified, instead of returning what appointment was on the row, it instead see which appointment the e.x and e.y intersects with (It's rectangle.) private IAppointment CheckForAppointment(MouseEventArgs e) { bool matchFound = false; IAppointment appointment = null; if (e.X < ApptOffset || e.X > panelDailyView.ClientRectangle.Size.Width - vScrollBar.Width - ApptOffset) { return(null); } IEnumerator <IAppointment> enumerator = _TodaysAppointments.GetEnumerator(); while (enumerator.MoveNext() && !matchFound) { if (_UiRect.Count() > 0 && _UiRect.ContainsKey(enumerator.Current) && _UiRect[enumerator.Current].Contains(e.Location)) { matchFound = true; appointment = enumerator.Current; } } return(appointment); }