/
Form1.cs
77 lines (70 loc) · 2.92 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#region #usings
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;
#endregion #usings
namespace HitTest
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
schedulerControl1.DayView.ShowWorkTimeOnly = true;
schedulerControl1.Start = DateTime.Now.Date;
schedulerControl1.DayView.GotoTimeInterval(new TimeInterval(schedulerControl1.Start.AddHours(17), new TimeSpan(2, 0, 0)));
LoadData();
}
private void LoadData()
{
Appointment apt = schedulerStorage1.CreateAppointment(AppointmentType.Normal);
apt.Subject = "Presentation";
apt.Start = schedulerControl1.Start.Date.AddHours(14);
apt.End = apt.Start.AddHours(3);
apt.Location = "Globus BookStore";
apt.Description = "The Sassanid Empire";
apt.LabelKey = 3;
schedulerStorage1.Appointments.Add(apt);
}
#region #hittest
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;
}
#endregion #hittest
}
}