【发布时间】:2020-12-06 21:48:33
【问题描述】:
使用此代码,它在文本上绘制突出显示,这会使文本以某种方式模糊?
Public Class HighlightableRTB
Inherits RichTextBox
Private LineHeight As Integer = 15
Public Sub New()
HighlightColor = Color.Yellow
End Sub
<Category("Custom"), Description("Specifies the highlight color.")>
Public Property HighlightColor As Color
Protected Overrides Sub OnSelectionChanged(ByVal e As EventArgs)
MyBase.OnSelectionChanged(e)
Me.Invalidate()
End Sub
Private Const WM_PAINT As Integer = 15
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_PAINT Then
Dim selectLength = Me.SelectionLength
Dim selectStart = Me.SelectionStart
Me.Invalidate()
MyBase.WndProc(m)
If selectLength > 0 Then Return
Using g As Graphics = Graphics.FromHwnd(Me.Handle)
Dim b As Brush = New SolidBrush(Color.FromArgb(50, HighlightColor))
Dim line = Me.GetLineFromCharIndex(selectStart)
Dim loc = Me.GetPositionFromCharIndex(Me.GetFirstCharIndexFromLine(line))
g.FillRectangle(b, New Rectangle(loc, New Size(Me.Width, LineHeight)))
End Using
Else
MyBase.WndProc(m)
End If
End Sub
End Class
如何在richtextbox的文本后面绘制矩形高亮?
【问题讨论】:
标签: vb.net richtextbox