This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
/
Form1.vb
56 lines (51 loc) · 1.96 KB
/
Form1.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
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports DevExpress.Spreadsheet
Imports DevExpress.Utils
Namespace SpreadsheetTooltip
Partial Public Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
InitializeComponent()
spreadsheetControl1.ToolTipController = toolTipController1
AddHandler toolTipController1.GetActiveObjectInfo, AddressOf ToolTipController1_GetActiveObjectInfo
spreadsheetControl1.LoadDocument("template.xlsx")
End Sub
Private Sub ToolTipController1_GetActiveObjectInfo(ByVal sender As Object, ByVal e As DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs)
If e.SelectedControl IsNot spreadsheetControl1 Then
Return
End If
Dim cell As Cell = spreadsheetControl1.GetCellFromPoint(New PointF(e.ControlMousePosition.X, e.ControlMousePosition.Y))
If cell Is Nothing Then
Return
End If
If cell.IsMerged Then
cell = cell.GetMergedRanges().First()(0)
End If
If Not cell.Value.IsEmpty Then
Dim info As New ToolTipControlInfo(cell, String.Empty)
info.ToolTipType = ToolTipType.SuperTip
Dim sToolTip As New SuperToolTip()
Dim item As New ToolTipItem()
item.Font = New Font("Arial", 10)
item.ImageOptions.SvgImage = svgImageCollection1(cell.Value.Type.ToString().ToLower())
item.Text = PrepareCellTooltip(cell)
sToolTip.Items.Add(item)
info.SuperTip = sToolTip
e.Info = info
End If
End Sub
Private Function PrepareCellTooltip(ByVal cell As Cell) As String
Dim cellReference As String = cell.GetReferenceA1()
Dim cellDataType As String = cell.Value.Type.ToString()
Dim cellDisplayText As String = cell.DisplayText
Return String.Format("Cell reference: {0}" & vbCrLf & "Data type: {1}" & vbCrLf & "Value: {2}", cellReference, cellDataType, cellDisplayText)
End Function
End Class
End Namespace