This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
HotTrackHelper.cs
65 lines (58 loc) · 2.08 KB
/
HotTrackHelper.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
using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Base;
using System.Windows.Forms;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraEditors;
using System.Drawing;
namespace E3803
{
class HotTrackHelper
{
GridView _view;
int hotRow = GridControl.InvalidRowHandle;
public HotTrackHelper(GridView view)
{
Attach(view);
}
void Attach(GridView view)
{
_view = view;
_view.CustomDrawCell += new RowCellCustomDrawEventHandler(_view_CustomDrawCell);
_view.MouseMove += new MouseEventHandler(_view_MouseMove);
}
void _view_MouseMove(object sender, MouseEventArgs e)
{
GridHitInfo hi = _view.CalcHitInfo(e.Location);
{
if (hotRow != hi.RowHandle)
{
_view.RefreshRow(hotRow);
hotRow = hi.RowHandle;
_view.RefreshRow(hotRow);
}
}
}
void _view_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
{
if (hotRow != e.RowHandle && e.RowHandle != _view.FocusedRowHandle) return;
GridCellInfo CellInfo = e.Cell as GridCellInfo;
SimpleButton button = new SimpleButton();
_view.GridControl.FindForm().Controls.Add(button);
button.Bounds = CellInfo.RowInfo.Bounds;
Bitmap bm = new Bitmap(button.Width, button.Height);
button.DrawToBitmap(bm, new Rectangle(0, 0, bm.Width, bm.Height));
Rectangle rec = Rectangle.Intersect(CellInfo.RowInfo.Bounds, CellInfo.CellValueRect);
rec.Offset(-CellInfo.RowInfo.Bounds.X, -CellInfo.RowInfo.Bounds.Y);
e.Cache.Paint.DrawImage(e.Cache.Graphics, bm, CellInfo.Bounds);
_view.GridControl.FindForm().Controls.Remove(button);
}
void Detach(GridView view)
{
_view = null;
}
}
}