HeaderPane
Main
Hide
Share Link
Print

Hit Testing

The SftDate.HitTest method returns the part of a field at a location, in client coordinates, as a FieldHitAreaEnum value: the check box, a part of the value (FieldHitAreaEnum.Segment), the text area outside a part, the Clear button, the dropdown button or the up and down buttons.

The SftCalendar.HitTest method returns a CalendarHitTestInfo object for a location in client coordinates. Its CalendarHitTestInfo.Area property (CalendarHitAreaEnum) tells what is at the location, such as a title, the previous or next button, a day, a day of the previous or next month, a week number, a month, year or decade in the larger views, or the Today and Clear buttons. Its CalendarHitTestInfo.Date property returns the date at the location.

C#

private void sftCalendar1_MouseDown(object sender, MouseEventArgs e) {
    if (e.Button != MouseButtons.Right) return;
    CalendarHitTestInfo hit = sftCalendar1.HitTest(e.Location);
    if (hit.Area == CalendarHitAreaEnum.Day)
        contextMenuStrip1.Show(sftCalendar1, e.Location);
}

VB

Private Sub SftCalendar1_MouseDown(sender As Object, e As MouseEventArgs) Handles SftCalendar1.MouseDown
    If e.Button <> MouseButtons.Right Then Return
    Dim hit As CalendarHitTestInfo = SftCalendar1.HitTest(e.Location)
    If hit.Area = CalendarHitAreaEnum.Day Then
        ContextMenuStrip1.Show(SftCalendar1, e.Location)
    End If
End Sub