-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
115 lines (99 loc) · 3.36 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.Utils.Drawing;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private DataTable CreateTable(int RowCount)
{
DataTable tbl = new DataTable();
tbl.Columns.Add("Name", typeof(string));
tbl.Columns.Add("ID", typeof(int));
tbl.Columns.Add("Number", typeof(int));
tbl.Columns.Add("Date", typeof(DateTime));
for (int i = 0; i < RowCount; i++)
tbl.Rows.Add(new object[] { String.Format("Name{0}", i), i, 3 - i, DateTime.Now.AddDays(i) });
return tbl;
}
public Form1()
{
InitializeComponent();
gridControl1.DataSource = CreateTable(20);
new HotTrackCellHelper(gridView1);
}
}
public class HotTrackCellHelper
{
public HotTrackCellHelper(GridView view)
{
_View = view;
view.GridControl.PaintEx += GridControl_PaintEx;
view.MouseMove += new MouseEventHandler(view_MouseMove);
}
private void GridControl_PaintEx(object sender, DevExpress.XtraGrid.PaintExEventArgs e)
{
DrawHotTrackedCell(e.Cache);
}
private int _BorderWidth = 4;
private GridCell _HotTrackedCell;
private readonly GridView _View;
public GridCell HotTrackedCell
{
get { return _HotTrackedCell; }
set
{
RefreshCell(_HotTrackedCell);
_HotTrackedCell = value;
}
}
public Rectangle GetCellBounds(GridCell cell)
{
if (cell == null)
return Rectangle.Empty;
GridViewInfo info = _View.GetViewInfo() as GridViewInfo;
GridCellInfo cellInfo = info.GetGridCellInfo(cell.RowHandle, cell.Column);
return cellInfo.Bounds;
}
private void UpdateHotTrackedCell(Point location)
{
GridHitInfo hi = _View.CalcHitInfo(location);
if (hi.HitTest == GridHitTest.Row || hi.HitTest == GridHitTest.RowEdge)
return;
if (hi.InRowCell)
{
if (_View.IsRowVisible(hi.RowHandle) == RowVisibleState.Visible)
{
HotTrackedCell = new GridCell(hi.RowHandle, hi.Column);
return;
}
}
HotTrackedCell = null;
}
void view_MouseMove(object sender, MouseEventArgs e)
{
UpdateHotTrackedCell(e.Location);
}
private void RefreshCell(GridCell cell)
{
if (cell == null)
return;
Rectangle rect = GetCellBounds(cell);
rect.Inflate(_BorderWidth, _BorderWidth);
_View.InvalidateRect(rect);
}
private void DrawHotTrackedCell(GraphicsCache cache)
{
Rectangle bounds = GetCellBounds(HotTrackedCell);
cache.DrawRectangle(new Pen(Brushes.Black, _BorderWidth), bounds);
}
}
}