默认情况下,我们都是用的微软的记事本,也就是txt文本,文本选中的背景颜色一直都是蓝色的,有木有?有很多人可能已经习惯了这种蓝色,但是也有人不想拘泥于这种颜色,想换一换、改变下心情。这里,小编给大家带来一款文本选定背景颜色修改工具,绝对实用。需要的朋友可以下载试试哦!
怎么修改文本选定背景颜色
文本选定背景颜色修改工具使用方法
Text的背景高亮色是蓝色不好看?还是RichTextBox的黑色好看,但Rich打开特殊字符会出错,怎么办呢?改了它即可,而且可以改成任意想要的颜色。通过测试,发现系统在调用一个SetBkColor的API,于是我们可以在它将要设置textbox的高亮色时吃掉它,改成自己的颜色。 依此类推,可以改变ListView的选定项背景或其它控件的颜色。
可以完美修改成你想要的任意颜色
文本选定背景颜色修改工具核心代码:
'********************* 改变TextBox选定背景色 *********************
VB代码,VB学习者可参考!
'frm_Main
Option Explicit
Private CustomColor(0 To 15) As Long
Private Sub Form_Load()
Text1.Text = "这是一个普通的TextBox"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
MyTBox.Text = "这是一个修改后的TextBox,该程序用来测试修改Text高亮背景色"
MyTBox.SelStart = 0
MyTBox.SelLength = Len(MyTBox.Text)
MyTBox.TabIndex = 0
g_TextHwnd = MyTBox.hWnd
g_NewColor = vbBlack
chkHook.Value = 1
Me.Show
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unhook
End Sub
Private Sub chkHook_Click()
g_Hook = chkHook.Value
MyTBox.Refresh
End Sub
Private Sub cmdColor_Click(Index As Integer)
If Index = 0 Then
g_NewColor = vbBlack
ElseIf Index = 1 Then
g_NewColor = vbRed
Else
'custom
Dim uColor&
uColor = ShowColorDialog(Me.hWnd, g_NewColor, CustomColor(0))
If uColor >= 0 Then g_NewColor = uColor
End If
MyTBox.Refresh
End Sub
'mod_Main
Option Explicit
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function GetSysColor Lib "user32.dll" (ByVal nIndex As Long) As Long
Private Declare Function WindowFromDC Lib "user32" (ByVal hdc As Long) As Long
Private MyHook As cls_HookApi '自定义hook
Private HighLightColor As Long
Public g_Hook As Boolean
Public g_TextHwnd As Long
Public g_NewColor As Long
Sub Main()
App.TaskVisible = False
m_InitSysColor '获取系统高亮颜色值
Set MyHook = New cls_HookApi
MyHook.HookApi "gdi32.dll", "SetBkColor", GetFunAddr(AddressOf SetBkColor_Callback), GetCurrentProcess
Load frm_Main
End Sub
'初始化系统颜色
Sub m_InitSysColor()
HighLightColor = GetSysColor(vbHighlight And &HFF)
End Sub
'回调
Public Function SetBkColor_Callback(ByVal hdc As Long, ByVal crColor As Long) As Long
MyHook.HookStatus False
If g_Hook Then
If WindowFromDC(hdc) = g_TextHwnd And crColor = HighLightColor Then
crColor = g_NewColor
End If
End If
SetBkColor_Callback = SetBkColor(hdc, crColor)
MyHook.HookStatus True
End Function
Public Function GetFunAddr(lngFunAddr As Long) As Long
GetFunAddr = lngFunAddr
End Function
Sub Unhook()
Set MyHook = Nothing
End Sub
- PC官方版
- 安卓官方手机版
- IOS官方手机版