The HitTest method returns what is at a location of a control, in pixels relative to the control's client area (HitTest, HitTest). Its return value tells what is at the location; for a calendar, its Date parameter returns the date there, or Null. The coordinates of the mouse events (MouseDown, MouseUp, MouseMove) can be passed as they are.
For an SftDate control, HitTest returns one of these values (see SftDateFieldHitConstants):
| Value | Location |
|---|---|
| fieldHitSftDateNowhere | Outside the field. |
| fieldHitSftDateSegment | A part of the value that can be edited. |
| fieldHitSftDateText | The text area outside a part, the text box of a field with free-form editing, or the text area of an empty field. |
| fieldHitSftDateCheckBox | The check box. |
| fieldHitSftDateClearButton | The Clear button. |
| fieldHitSftDateDropDownButton | The dropdown button. |
| fieldHitSftDateUpButton, fieldHitSftDateDownButton | The up and down buttons. |
The Date parameter returns Null for a field. The dropdown is a window of its own and is not part of the field's client area; points in the dropdown return fieldHitSftDateNowhere.
For an SftCalendar control, HitTest returns one of these values (see SftDateCalendarHitConstants):
| Value | Location |
|---|---|
| calHitSftDateNowhere | Outside the calendar. |
| calHitSftDateBackground | The background, outside the other parts. |
| calHitSftDateTitle | The title of a month, a year, a decade or a century; Date is the first date of the period. |
| calHitSftDatePreviousButton, calHitSftDateNextButton | The previous and next buttons. |
| calHitSftDateDayOfWeek | The name of a day of the week. |
| calHitSftDateWeekNumber | A week number; Date is the first date of the week's row. |
| calHitSftDateDay | A day of a month; Date is the day. |
| calHitSftDateTrailingDay | A day of the previous or next month; Date is the day. |
| calHitSftDatePeriod | A month, a year or a decade in the larger views; Date is the first date of the period. |
| calHitSftDateTodayButton, calHitSftDateClearButton | The Today and Clear buttons. |
This example shows a context menu (menuDay, a ContextMenuStrip of the form) when the user right-clicks a day:
private void sftCalendar1_MouseUpEvent(object sender, AxSftDateLib20._ISftCalendarEvents_MouseUpEvent e) {
if (e.button != (short)SftControlButtonConstants.constSftControlRightButton)
return;
object date;
if (sftCalendar1.HitTest(e.xPos, e.yPos, out date) == SftDateCalendarHitConstants.calHitSftDateDay) {
menuDay.Tag = date; // the day the menu's commands apply to
menuDay.Show(sftCalendar1, new Point(e.xPos, e.yPos));
}
}