This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
/
HotTrackHelper.vb
59 lines (52 loc) · 1.88 KB
/
HotTrackHelper.vb
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
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Base
Imports System.Windows.Forms
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.XtraEditors
Imports System.Drawing
Namespace E3803
Friend Class HotTrackHelper
Private _view As GridView
Private hotRow As Integer = GridControl.InvalidRowHandle
Public Sub New(ByVal view As GridView)
Attach(view)
End Sub
Private Sub Attach(ByVal view As GridView)
_view = view
AddHandler _view.CustomDrawCell, AddressOf _view_CustomDrawCell
AddHandler _view.MouseMove, AddressOf _view_MouseMove
End Sub
Private Sub _view_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim hi As GridHitInfo = _view.CalcHitInfo(e.Location)
If True Then
If hotRow <> hi.RowHandle Then
_view.RefreshRow(hotRow)
hotRow = hi.RowHandle
_view.RefreshRow(hotRow)
End If
End If
End Sub
Private Sub _view_CustomDrawCell(ByVal sender As Object, ByVal e As RowCellCustomDrawEventArgs)
If hotRow <> e.RowHandle AndAlso e.RowHandle <> _view.FocusedRowHandle Then
Return
End If
Dim CellInfo As GridCellInfo = TryCast(e.Cell, GridCellInfo)
Dim button As New SimpleButton()
_view.GridControl.FindForm().Controls.Add(button)
button.Bounds = CellInfo.RowInfo.Bounds
Dim bm As New Bitmap(button.Width, button.Height)
button.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height))
Dim rec As Rectangle = 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)
End Sub
Private Sub Detach(ByVal view As GridView)
_view = Nothing
End Sub
End Class
End Namespace