add Highlighter
This commit is contained in:
163
Pilz.UI/DisplayHelp.vb
Normal file
163
Pilz.UI/DisplayHelp.vb
Normal file
@@ -0,0 +1,163 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Drawing.Drawing2D
|
||||
|
||||
Public Class DisplayHelp
|
||||
|
||||
Public Shared Sub FillRectangle(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal color1 As Color)
|
||||
FillRectangle(g, bounds, color1, Color.Empty, 90)
|
||||
End Sub
|
||||
|
||||
Public Shared Sub FillRectangle(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal color1 As Color, ByVal color2 As Color)
|
||||
FillRectangle(g, bounds, color1, color2, 90)
|
||||
End Sub
|
||||
|
||||
Public Shared Sub FillRectangle(ByVal g As Graphics, ByVal r As Rectangle, ByVal color1 As Color, ByVal color2 As Color, ByVal gradientAngle As Integer)
|
||||
If r.Width = 0 OrElse r.Height = 0 Then Return
|
||||
|
||||
If color2.IsEmpty Then
|
||||
|
||||
If Not color1.IsEmpty Then
|
||||
Dim sm As SmoothingMode = g.SmoothingMode
|
||||
g.SmoothingMode = SmoothingMode.None
|
||||
|
||||
Using brush As SolidBrush = New SolidBrush(color1)
|
||||
g.FillRectangle(brush, r)
|
||||
End Using
|
||||
|
||||
g.SmoothingMode = sm
|
||||
End If
|
||||
Else
|
||||
|
||||
Using brush As LinearGradientBrush = CreateLinearGradientBrush(r, color1, color2, gradientAngle)
|
||||
g.FillRectangle(brush, r)
|
||||
End Using
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Sub FillRectangle(ByVal g As Graphics, ByVal r As Rectangle, ByVal color1 As Color, ByVal color2 As Color, ByVal gradientAngle As Integer, ByVal factors As Single(), ByVal positions As Single())
|
||||
If r.Width = 0 OrElse r.Height = 0 Then Return
|
||||
|
||||
If color2.IsEmpty Then
|
||||
|
||||
If Not color1.IsEmpty Then
|
||||
Dim sm As SmoothingMode = g.SmoothingMode
|
||||
g.SmoothingMode = SmoothingMode.None
|
||||
|
||||
Using brush As SolidBrush = New SolidBrush(color1)
|
||||
g.FillRectangle(brush, r)
|
||||
End Using
|
||||
|
||||
g.SmoothingMode = sm
|
||||
End If
|
||||
Else
|
||||
|
||||
Using brush As LinearGradientBrush = CreateLinearGradientBrush(r, color1, color2, gradientAngle)
|
||||
Dim blend As Blend = New Blend(factors.Length)
|
||||
blend.Factors = factors
|
||||
blend.Positions = positions
|
||||
brush.Blend = blend
|
||||
g.FillRectangle(brush, r)
|
||||
End Using
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Sub FillRoundedRectangle(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal cornerSize As Integer, ByVal color1 As Color, ByVal color2 As Color, ByVal gradientAngle As Integer)
|
||||
If color2.IsEmpty Then
|
||||
|
||||
If Not color1.IsEmpty Then
|
||||
|
||||
Using brush As SolidBrush = New SolidBrush(color1)
|
||||
FillRoundedRectangle(g, brush, bounds, cornerSize)
|
||||
End Using
|
||||
End If
|
||||
Else
|
||||
|
||||
Using brush As LinearGradientBrush = CreateLinearGradientBrush(bounds, color1, color2, gradientAngle)
|
||||
FillRoundedRectangle(g, brush, bounds, cornerSize)
|
||||
End Using
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Sub FillRoundedRectangle(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal cornerSize As Integer, ByVal color1 As Color, ByVal color2 As Color)
|
||||
FillRoundedRectangle(g, bounds, cornerSize, color1, color2, 90)
|
||||
End Sub
|
||||
|
||||
Public Shared Sub FillRoundedRectangle(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal cornerSize As Integer, ByVal color1 As Color)
|
||||
Using brush As SolidBrush = New SolidBrush(color1)
|
||||
FillRoundedRectangle(g, brush, bounds, cornerSize)
|
||||
End Using
|
||||
End Sub
|
||||
|
||||
Public Shared Sub FillRoundedRectangle(ByVal g As Graphics, ByVal brush As Brush, ByVal bounds As Rectangle, ByVal cornerSize As Integer)
|
||||
If cornerSize <= 0 Then
|
||||
Dim sm As SmoothingMode = g.SmoothingMode
|
||||
g.SmoothingMode = SmoothingMode.None
|
||||
g.FillRectangle(brush, bounds)
|
||||
g.SmoothingMode = sm
|
||||
Else
|
||||
bounds.Width -= 1
|
||||
bounds.Height -= 1
|
||||
|
||||
Using path As GraphicsPath = GetRoundedRectanglePath(bounds, cornerSize)
|
||||
g.FillPath(brush, path)
|
||||
End Using
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Sub DrawRectangle(ByVal g As System.Drawing.Graphics, ByVal color As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
|
||||
Using pen As Pen = New Pen(color, 1)
|
||||
DrawRectangle(g, pen, x, y, width, height)
|
||||
End Using
|
||||
End Sub
|
||||
|
||||
Public Shared Sub DrawRectangle(ByVal g As System.Drawing.Graphics, ByVal color As Color, ByVal r As System.Drawing.Rectangle)
|
||||
DrawRectangle(g, color, r.X, r.Y, r.Width, r.Height)
|
||||
End Sub
|
||||
|
||||
Public Shared Sub DrawRectangle(ByVal g As System.Drawing.Graphics, ByVal pen As System.Drawing.Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
|
||||
width -= 1
|
||||
height -= 1
|
||||
g.DrawRectangle(pen, x, y, width, height)
|
||||
End Sub
|
||||
|
||||
Public Shared Sub DrawRoundedRectangle(ByVal g As System.Drawing.Graphics, ByVal color As Color, ByVal bounds As Rectangle, ByVal cornerSize As Integer)
|
||||
If Not color.IsEmpty Then
|
||||
|
||||
Using pen As Pen = New Pen(color)
|
||||
DrawRoundedRectangle(g, pen, bounds.X, bounds.Y, bounds.Width, bounds.Height, cornerSize)
|
||||
End Using
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Sub DrawRoundedRectangle(ByVal g As System.Drawing.Graphics, ByVal pen As System.Drawing.Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cornerSize As Integer)
|
||||
DrawRoundedRectangle(g, pen, Nothing, x, y, width, height, cornerSize)
|
||||
End Sub
|
||||
|
||||
Public Shared Sub DrawRoundedRectangle(ByVal g As System.Drawing.Graphics, ByVal pen As System.Drawing.Pen, ByVal fill As Brush, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cornerSize As Integer)
|
||||
width -= 1
|
||||
height -= 1
|
||||
Dim r As Rectangle = New Rectangle(x, y, width, height)
|
||||
|
||||
Using path As GraphicsPath = GetRoundedRectanglePath(r, cornerSize)
|
||||
If fill IsNot Nothing Then g.FillPath(fill, path)
|
||||
g.DrawPath(pen, path)
|
||||
End Using
|
||||
End Sub
|
||||
|
||||
Public Shared Function GetRoundedRectanglePath(ByVal r As Rectangle, ByVal cornerSize As Integer) As GraphicsPath
|
||||
Dim path As GraphicsPath = New GraphicsPath()
|
||||
|
||||
If cornerSize = 0 Then
|
||||
path.AddRectangle(r)
|
||||
End If
|
||||
|
||||
Return path
|
||||
End Function
|
||||
|
||||
Public Shared Function CreateLinearGradientBrush(ByVal r As Rectangle, ByVal color1 As Color, ByVal color2 As Color, ByVal gradientAngle As Single) As LinearGradientBrush
|
||||
If r.Width <= 0 Then r.Width = 1
|
||||
If r.Height <= 0 Then r.Height = 1
|
||||
Return New LinearGradientBrush(New Rectangle(r.X, r.Y - 1, r.Width, r.Height + 1), color1, color2, gradientAngle)
|
||||
End Function
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user