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 0
/
ScrollPreviewControl.vb
54 lines (47 loc) · 1.52 KB
/
ScrollPreviewControl.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
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.XtraGrid.Views.Grid
Namespace WindowsApplication1
Partial Public Class ScrollPreviewControl
Inherits UserControl
Private _View As GridView
Public Sub New()
InitializeComponent()
End Sub
Public Sub RegisterGridView(ByVal view As GridView)
_View = view
AddHandler view.TopRowChanged, AddressOf view_TopRowChanged
AddHandler view.LeftCoordChanged, AddressOf view_LeftCoordChanged
End Sub
Private Sub view_LeftCoordChanged(ByVal sender As Object, ByVal e As EventArgs)
OnViewScrolled()
End Sub
Private Sub view_TopRowChanged(ByVal sender As Object, ByVal e As EventArgs)
OnViewScrolled()
End Sub
Private Sub OnViewScrolled()
Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
If _View IsNot Nothing Then
Dim totalAreaRect As Rectangle = _View.GetAllCellsArea()
Dim dx As Double = Width * 1.0 / totalAreaRect.Width
Dim dy As Double = Height * 1.0 / totalAreaRect.Height
Dim rect As Rectangle = _View.GetVisibleCells()
rect.Y = Convert.ToInt32(rect.Y * dy)
rect.Height = Convert.ToInt32(rect.Height * dy)
rect.Width = Convert.ToInt32(rect.Width * dx)
rect.X = Convert.ToInt32(rect.X * dx)
e.Graphics.DrawRectangle(Pens.Red, rect)
End If
End Sub
End Class
End Namespace