Back to Devexpress

SchedulerViewInfoBase.CalcHitInfo(Point, Boolean) Method

windowsforms-devexpress-dot-xtrascheduler-dot-drawing-dot-schedulerviewinfobase-dot-calchitinfo-x28-system-dot-drawing-dot-point-system-dot-boolean-x29.md

latest9.6 KB
Original Source

SchedulerViewInfoBase.CalcHitInfo(Point, Boolean) Method

Returns information on scheduler elements located at the specified point.

Namespace : DevExpress.XtraScheduler.Drawing

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public virtual SchedulerHitInfo CalcHitInfo(
    Point pt,
    bool layoutOnly
)
vb
Public Overridable Function CalcHitInfo(
    pt As Point,
    layoutOnly As Boolean
) As SchedulerHitInfo

Parameters

NameTypeDescription
ptPoint

A Point structure which specifies the test point coordinates relative to the scheduler’s top-left corner.

| | layoutOnly | Boolean |

true if the appointments are ignored and only the scheduler’s layout is taken into consideration; otherwise, false.

|

Returns

TypeDescription
SchedulerHitInfo

A SchedulerHitInfo object which contains information about scheduler elements located at the test point.

|

Remarks

Use the CalcHitInfo method to determine which element is located at the specified point. For instance, this can be used when handling the scheduler’s Click event to determine which element was clicked. In such cases, pass the current mouse pointer’s coordinates as the method’s parameter.

To know what element is located below the appointment being clicked, set the layoutOnly parameter of the CalcHitInfo function to true.

If you drag objects from other controls on the form, use the PointToClient, to convert coordinates before using the CalcHitInfo method. The following code line enables you to get an appointment to which an object is dragged:

csharp
SchedulerHitInfo hitInfo = schedulerControl.ActiveView.ViewInfo.CalcHitInfo(
schedulerControl.PointToClient(Form.MousePosition),false);
vb
Dim hitInfo As SchedulerHitInfo = schedulerControl.ActiveView.ViewInfo.CalcHitInfo( _
schedulerControl.PointToClient(Form.MousePosition),False)

Example

The following examples demonstrate how to handle the SchedulerControl.MouseMove event and calculate the hit information for the point which the mouse pointer is currently hovering over. The information on the element located under the mouse pointer is shown within the form caption.

The second parameter of the SchedulerViewInfoBase.CalcHitInfo method enables you to specify whether you need information on an appointment being clicked, or on a scheduler element located underneath.

When you drag an appointment over the scheduler, you can use the SchedulerViewInfoBase.CalcHitInfo method to determine the scheduler area below. If you drag appointment to the All-Day Area, you can cancel the action.

View Example

csharp
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;
        private void schedulerControl1_MouseMove(object sender, MouseEventArgs e)
        {
            SchedulerControl scheduler = sender as SchedulerControl;
            if (scheduler == null) return;

            Point pos = new Point(e.X, e.Y);
            SchedulerViewInfoBase viewInfo = schedulerControl1.ActiveView.ViewInfo;
            SchedulerHitInfo hitInfo = viewInfo.CalcHitInfo(pos, false);

            if (hitInfo.HitTest == SchedulerHitTest.AppointmentContent)
            {
                Appointment apt = ((AppointmentViewInfo)hitInfo.ViewInfo).Appointment;
                Text = apt.Subject;
            }
            else if (scheduler.ActiveView.Type == SchedulerViewType.Day && hitInfo.HitTest == SchedulerHitTest.Cell)
            {
                int diff = pos.Y - hitInfo.ViewInfo.Bounds.Y;
                long ticksPerPixel = hitInfo.ViewInfo.Interval.Duration.Ticks /
                    hitInfo.ViewInfo.Bounds.Height;
                long ticksCount = ticksPerPixel * diff;
                DateTime actualTime = hitInfo.ViewInfo.Interval.Start.AddTicks(ticksCount);
                Text = actualTime.ToString();
            }
            else if (hitInfo.HitTest == SchedulerHitTest.None)
            {
                Text = Application.ProductName;
            }
            else Text = string.Empty;
        }

        private void schedulerControl1_DragOver(object sender, DragEventArgs e)
        {
            SchedulerControl scheduler = sender as SchedulerControl;
            if (scheduler == null) return;

            Point p = scheduler.PointToClient(new Point(e.X, e.Y));
            SchedulerHitInfo info = scheduler.DayView.ViewInfo.CalcHitInfo(p, true);
            if (info.HitTest == SchedulerHitTest.AllDayArea)
                e.Effect = DragDropEffects.None;
        }
vb
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Drawing
Imports System
Imports System.Drawing
Imports System.Windows.Forms
        Private Sub schedulerControl1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles schedulerControl1.MouseMove
            Dim scheduler As SchedulerControl = TryCast(sender, SchedulerControl)
            If scheduler Is Nothing Then
                Return
            End If

            Dim pos As New Point(e.X, e.Y)
            Dim viewInfo As SchedulerViewInfoBase = schedulerControl1.ActiveView.ViewInfo
            Dim hitInfo As SchedulerHitInfo = viewInfo.CalcHitInfo(pos, False)

            If hitInfo.HitTest = SchedulerHitTest.AppointmentContent Then
                Dim apt As Appointment = CType(hitInfo.ViewInfo, AppointmentViewInfo).Appointment
                Text = apt.Subject
            ElseIf scheduler.ActiveView.Type = SchedulerViewType.Day AndAlso hitInfo.HitTest = SchedulerHitTest.Cell Then
                Dim diff As Integer = pos.Y - hitInfo.ViewInfo.Bounds.Y
                Dim ticksPerPixel = hitInfo.ViewInfo.Interval.Duration.Ticks / hitInfo.ViewInfo.Bounds.Height
                Dim ticksCount = CType(ticksPerPixel * diff, Long)
                Dim actualTime As Date = hitInfo.ViewInfo.Interval.Start.AddTicks(ticksCount)
                Text = actualTime.ToString()
            ElseIf hitInfo.HitTest = SchedulerHitTest.None Then
                Text = Application.ProductName
            Else
                Text = String.Empty
            End If
        End Sub

        Private Sub schedulerControl1_DragOver(ByVal sender As Object, ByVal e As DragEventArgs) Handles schedulerControl1.DragOver
            Dim scheduler As SchedulerControl = TryCast(sender, SchedulerControl)
            If scheduler Is Nothing Then
                Return
            End If

            Dim p As Point = scheduler.PointToClient(New Point(e.X, e.Y))
            Dim info As SchedulerHitInfo = scheduler.DayView.ViewInfo.CalcHitInfo(p, True)
            If info.HitTest = SchedulerHitTest.AllDayArea Then
                e.Effect = DragDropEffects.None
            End If
        End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CalcHitInfo(Point, Boolean) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-scheduler-hit-testing/CS/HitTest/Form1.cs#L42

csharp
SchedulerViewInfoBase viewInfo = schedulerControl1.ActiveView.ViewInfo;
SchedulerHitInfo hitInfo = viewInfo.CalcHitInfo(pos, false);

winforms-scheduler-hit-testing/VB/HitTest/Form1.vb#L41

vb
Dim viewInfo As SchedulerViewInfoBase = schedulerControl1.ActiveView.ViewInfo
Dim hitInfo As SchedulerHitInfo = viewInfo.CalcHitInfo(pos, False)

See Also

SchedulerViewInfoBase Class

SchedulerViewInfoBase Members

DevExpress.XtraScheduler.Drawing Namespace