This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Form1.cs
53 lines (48 loc) · 1.95 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
namespace HorzLineIndicator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
schedulerControl1.DayView.DayCount = 3;
schedulerControl1.Services.DateTimeNavigation.GoToToday();
schedulerControl1.DayView.TopRowTime = new TimeSpan((DateTime.Now.Hour - 1), 0,0);
}
private void schedulerControl1_CustomDrawTimeCell(object sender, DevExpress.XtraScheduler.CustomDrawObjectEventArgs e)
{
SchedulerViewType viewType = ((SchedulerControl)sender).ActiveViewType;
// Draw a line in the Day and WorkWeek views only.
bool drawHorzLine = viewType == SchedulerViewType.Day || viewType == SchedulerViewType.WorkWeek;
if (!drawHorzLine)
return;
TimeInterval interval = ((TimeCell)e.ObjectInfo).Interval;
DateTime now = interval.Start.Date + DateTime.Now.TimeOfDay;
Rectangle nowRect = Rectangle.Empty;
// For each timecell drawn check whether the current time falls in its interval.
if (interval.Contains(now))
{
e.DrawDefault();
Rectangle rect = e.Bounds;
nowRect = rect;
// Calculate offset from the timecell's top.
TimeSpan nowOffset = now.TimeOfDay - interval.Start.TimeOfDay;
float offsetRatio = nowOffset.Ticks / (float)interval.Duration.Ticks;
nowRect.Y += (int)(rect.Height * offsetRatio);
// Set the line thickness.
nowRect.Height = 1;
e.Cache.FillRectangle(Color.Red, nowRect);
e.Handled = true;
}
}
}
}