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 If cornerSize = 0 Then
path.AddRectangle(r) 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 End If
Return path 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) Return New LinearGradientBrush(New Rectangle(r.X, r.Y - 1, r.Width, r.Height + 1), color1, color2, gradientAngle)
End Function 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 End Class

View File

@@ -160,7 +160,7 @@ Friend Class HighlightPanel
If rgb = -1 Then If rgb = -1 Then
Return Color.Empty Return Color.Empty
Else 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 If
End Function End Function
@@ -168,7 +168,7 @@ Friend Class HighlightPanel
If rgb = -1 Then If rgb = -1 Then
Return Color.Empty Return Color.Empty
Else 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 If
End Function End Function
@@ -220,9 +220,9 @@ Friend Class HighlightPanel
Public HighlightColor As eHighlightColor Public HighlightColor As eHighlightColor
Public Sub New(ByVal bounds As Rectangle, ByVal backColor As Color, ByVal highlightColor As eHighlightColor) Public Sub New(ByVal bounds As Rectangle, ByVal backColor As Color, ByVal highlightColor As eHighlightColor)
bounds = bounds Me.Bounds = bounds
backColor = backColor Me.BackColor = backColor
highlightColor = highlightColor Me.HighlightColor = highlightColor
End Sub End Sub
End Structure End Structure

View File

@@ -320,24 +320,26 @@ Public Class Highlighter
Private Sub UpdateHighlightPanelBounds() Private Sub UpdateHighlightPanelBounds()
Dim bounds As Rectangle = New Rectangle(0, 0, _ContainerControl.ClientRectangle.Width, _ContainerControl.ClientRectangle.Height) Dim bounds As Rectangle = New Rectangle(0, 0, _ContainerControl.ClientRectangle.Width, _ContainerControl.ClientRectangle.Height)
If TypeOf _HighlightPanel.Parent Is Form Then If _HighlightPanel IsNot Nothing Then
Dim form As Form = TryCast(_HighlightPanel.Parent, Form) If TypeOf _HighlightPanel.Parent Is Form Then
Dim form As Form = TryCast(_HighlightPanel.Parent, Form)
If form.AutoSize Then If form.AutoSize Then
bounds.X += form.Padding.Left bounds.X += form.Padding.Left
bounds.Y += form.Padding.Top bounds.Y += form.Padding.Top
bounds.Width -= form.Padding.Horizontal bounds.Width -= form.Padding.Horizontal
bounds.Height -= form.Padding.Vertical bounds.Height -= form.Padding.Vertical
End If
End If End If
End If
If _HighlightPanel.Bounds.Equals(bounds) Then If _HighlightPanel.Bounds.Equals(bounds) Then
_HighlightPanel.UpdateRegion() _HighlightPanel.UpdateRegion()
Else Else
_HighlightPanel.Bounds = bounds _HighlightPanel.Bounds = bounds
End If End If
_HighlightPanel.BringToFront() _HighlightPanel.BringToFront()
End If
End Sub End Sub
Private _DelayTimer As Timer = Nothing Private _DelayTimer As Timer = Nothing
@@ -386,17 +388,6 @@ Public Class Highlighter
End Set End Set
End Property 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 End Class
Public Enum eHighlightColor Public Enum eHighlightColor