找了些方法,只能改变行中字符的颜色,暂时没找到改变一行背景的颜色,在这里求助大家了。
4 个解决方案
#1
自己实现了,谢谢CSDN的帖子,在帖子中找到了方法,自己捉摸实现了。
#2
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cf As New CHARFORMAT2A
Dim colr As Color = Color.Red
Dim ret As Integer
With cf
.cbSize = Marshal.SizeOf(cf) 'setup the size of the character format
.dwMask = CFM_BACKCOLOR 'what to test
.crBackColor = Drawing.ColorTranslator.ToWin32(colr)
ret = SendMessage(Me.RichTextBox1.Handle, EM_SETCHARFORMAT, SCF_SELECTION, cf)
End With 'CF
End Sub
Private Const WM_USER As Integer = &H400
Private Const CFM_BACKCOLOR As Integer = &H4000000
Private Const EM_GETCHARFORMAT As Integer = (WM_USER + 58)
Private Const EM_SETCHARFORMAT As Integer = (WM_USER + 68)
Private Const SCF_SELECTION As Integer = &H1&
Private Const LF_FACESIZE As Integer = 32
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As CHARFORMAT2A) As Integer
<StructLayout(LayoutKind.Sequential, Pack:=4)> _
Public Class CHARFORMAT2A
Public cbSize As Integer = Marshal.SizeOf(GetType(CHARFORMAT2A))
Public dwMask As Integer
Public dwEffects As Integer
Public yHeight As Integer
Public yOffset As Integer
Public crTextColor As Integer
Public bCharSet As Byte
Public bPitchAndFamily As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=&H20)> _
Public szFaceName As Byte() = New Byte(&H20 - 1) {}
Public wWeight As Short
Public sSpacing As Short
Public crBackColor As Integer
Public lcid As Integer
Public dwReserved As Integer
Public sStyle As Short
Public wKerning As Short
Public bUnderlineType As Byte
Public bAnimation As Byte
Public bRevAuthor As Byte
End Class
End Class
#3
#4
楼主能不能分享一下你的实现方法,感激不尽!!!!!!!!!!1
#1
自己实现了,谢谢CSDN的帖子,在帖子中找到了方法,自己捉摸实现了。
#2
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cf As New CHARFORMAT2A
Dim colr As Color = Color.Red
Dim ret As Integer
With cf
.cbSize = Marshal.SizeOf(cf) 'setup the size of the character format
.dwMask = CFM_BACKCOLOR 'what to test
.crBackColor = Drawing.ColorTranslator.ToWin32(colr)
ret = SendMessage(Me.RichTextBox1.Handle, EM_SETCHARFORMAT, SCF_SELECTION, cf)
End With 'CF
End Sub
Private Const WM_USER As Integer = &H400
Private Const CFM_BACKCOLOR As Integer = &H4000000
Private Const EM_GETCHARFORMAT As Integer = (WM_USER + 58)
Private Const EM_SETCHARFORMAT As Integer = (WM_USER + 68)
Private Const SCF_SELECTION As Integer = &H1&
Private Const LF_FACESIZE As Integer = 32
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As CHARFORMAT2A) As Integer
<StructLayout(LayoutKind.Sequential, Pack:=4)> _
Public Class CHARFORMAT2A
Public cbSize As Integer = Marshal.SizeOf(GetType(CHARFORMAT2A))
Public dwMask As Integer
Public dwEffects As Integer
Public yHeight As Integer
Public yOffset As Integer
Public crTextColor As Integer
Public bCharSet As Byte
Public bPitchAndFamily As Byte
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=&H20)> _
Public szFaceName As Byte() = New Byte(&H20 - 1) {}
Public wWeight As Short
Public sSpacing As Short
Public crBackColor As Integer
Public lcid As Integer
Public dwReserved As Integer
Public sStyle As Short
Public wKerning As Short
Public bUnderlineType As Byte
Public bAnimation As Byte
Public bRevAuthor As Byte
End Class
End Class
#3
#4
楼主能不能分享一下你的实现方法,感激不尽!!!!!!!!!!1