fix highlighter

This commit is contained in:
2022-06-27 21:33:24 +02:00
parent 68f26c6c9f
commit efb522d842
3 changed files with 90 additions and 30 deletions

View File

@@ -149,6 +149,12 @@ Public Class DisplayHelp
If cornerSize = 0 Then
path.AddRectangle(r)
Else
AddCornerArc(path, r, cornerSize, eCornerArc.TopLeft)
AddCornerArc(path, r, cornerSize, eCornerArc.TopRight)
AddCornerArc(path, r, cornerSize, eCornerArc.BottomRight)
AddCornerArc(path, r, cornerSize, eCornerArc.BottomLeft)
path.CloseAllFigures()
End If
Return path
@@ -160,4 +166,67 @@ Public Class DisplayHelp
Return New LinearGradientBrush(New Rectangle(r.X, r.Y - 1, r.Width, r.Height + 1), color1, color2, gradientAngle)
End Function
Public Shared Sub AddCornerArc(ByVal path As GraphicsPath, ByVal bounds As Rectangle, ByVal cornerDiameter As Integer, ByVal corner As eCornerArc)
If cornerDiameter > 0 Then
Dim a As ArcData = GetCornerArc(bounds, cornerDiameter, corner)
path.AddArc(a.X, a.Y, a.Width, a.Height, a.StartAngle, a.SweepAngle)
Else
If corner = eCornerArc.TopLeft Then
path.AddLine(bounds.X, bounds.Y + 2, bounds.X, bounds.Y)
ElseIf corner = eCornerArc.BottomLeft Then
path.AddLine(bounds.X + 2, bounds.Bottom, bounds.X, bounds.Bottom)
ElseIf corner = eCornerArc.TopRight Then
path.AddLine(bounds.Right - 2, bounds.Y, bounds.Right, bounds.Y)
ElseIf corner = eCornerArc.BottomRight Then
path.AddLine(bounds.Right, bounds.Bottom - 2, bounds.Right, bounds.Bottom)
End If
End If
End Sub
Friend Shared Function GetCornerArc(ByVal bounds As Rectangle, ByVal cornerDiameter As Integer, ByVal corner As eCornerArc) As ArcData
Dim a As ArcData
If cornerDiameter = 0 Then cornerDiameter = 1
Dim diameter As Integer = cornerDiameter * 2
Select Case corner
Case eCornerArc.TopLeft
a = New ArcData(bounds.X, bounds.Y, diameter, diameter, 180, 90)
Case eCornerArc.TopRight
a = New ArcData(bounds.Right - diameter, bounds.Y, diameter, diameter, 270, 90)
Case eCornerArc.BottomLeft
a = New ArcData(bounds.X, bounds.Bottom - diameter, diameter, diameter, 90, 90)
Case Else
a = New ArcData(bounds.Right - diameter, bounds.Bottom - diameter, diameter, diameter, 0, 90)
End Select
Return a
End Function
Public Enum eCornerArc
TopLeft
TopRight
BottomLeft
BottomRight
End Enum
Friend Structure ArcData
Public X As Integer
Public Y As Integer
Public Width As Integer
Public Height As Integer
Public StartAngle As Single
Public SweepAngle As Single
Public Sub New(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal startAngle As Single, ByVal sweepAngle As Single)
Me.X = x
Me.Y = y
Me.Width = width
Me.Height = height
Me.StartAngle = startAngle
Me.SweepAngle = sweepAngle
End Sub
End Structure
End Class

View File

@@ -160,7 +160,7 @@ Friend Class HighlightPanel
If rgb = -1 Then
Return Color.Empty
Else
Return Color.FromArgb((rgb And &HFF0000) >> 16, (rgb And &HFF00) >> 8, rgb & &HFF)
Return Color.FromArgb((rgb And &HFF0000) >> 16, (rgb And &HFF00) >> 8, rgb And &HFF)
End If
End Function
@@ -168,7 +168,7 @@ Friend Class HighlightPanel
If rgb = -1 Then
Return Color.Empty
Else
Return Color.FromArgb(alpha, (rgb And &HFF0000) >> 16, (rgb And &HFF00) >> 8, rgb & &HFF)
Return Color.FromArgb(alpha, (rgb And &HFF0000) >> 16, (rgb And &HFF00) >> 8, rgb And &HFF)
End If
End Function
@@ -220,9 +220,9 @@ Friend Class HighlightPanel
Public HighlightColor As eHighlightColor
Public Sub New(ByVal bounds As Rectangle, ByVal backColor As Color, ByVal highlightColor As eHighlightColor)
bounds = bounds
backColor = backColor
highlightColor = highlightColor
Me.Bounds = bounds
Me.BackColor = backColor
Me.HighlightColor = highlightColor
End Sub
End Structure

View File

@@ -320,24 +320,26 @@ Public Class Highlighter
Private Sub UpdateHighlightPanelBounds()
Dim bounds As Rectangle = New Rectangle(0, 0, _ContainerControl.ClientRectangle.Width, _ContainerControl.ClientRectangle.Height)
If TypeOf _HighlightPanel.Parent Is Form Then
Dim form As Form = TryCast(_HighlightPanel.Parent, Form)
If _HighlightPanel IsNot Nothing Then
If TypeOf _HighlightPanel.Parent Is Form Then
Dim form As Form = TryCast(_HighlightPanel.Parent, Form)
If form.AutoSize Then
bounds.X += form.Padding.Left
bounds.Y += form.Padding.Top
bounds.Width -= form.Padding.Horizontal
bounds.Height -= form.Padding.Vertical
If form.AutoSize Then
bounds.X += form.Padding.Left
bounds.Y += form.Padding.Top
bounds.Width -= form.Padding.Horizontal
bounds.Height -= form.Padding.Vertical
End If
End If
End If
If _HighlightPanel.Bounds.Equals(bounds) Then
_HighlightPanel.UpdateRegion()
Else
_HighlightPanel.Bounds = bounds
End If
If _HighlightPanel.Bounds.Equals(bounds) Then
_HighlightPanel.UpdateRegion()
Else
_HighlightPanel.Bounds = bounds
End If
_HighlightPanel.BringToFront()
_HighlightPanel.BringToFront()
End If
End Sub
Private _DelayTimer As Timer = Nothing
@@ -386,17 +388,6 @@ Public Class Highlighter
End Set
End Property
Public Function CanExtend(ByVal extendee As Object) As Boolean
Return (TypeOf extendee Is Control)
End Function
Private Sub SetError(ByVal control As Control, ByVal value As String)
Me.SetHighlightColor(control, eHighlightColor.Red)
End Sub
Private Sub ClearError(ByVal control As Control)
Me.SetHighlightColor(control, eHighlightColor.None)
End Sub
End Class
Public Enum eHighlightColor