Option Explicit

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type DRAWITEMSTRUCT
CtlType As Long '控件类型
CtlID As Long '控件ID
itemID As Long '菜单项、列表框或组合框中某一项的索引值
itemAction As Long '控件行为
itemState As Long '控件状态
hwndItem As Long '父窗口句柄或菜单句柄
hdc As Long '控件对应的绘图设备句柄
rcItem As RECT '控件所占据的矩形区域
itemData As Long '列表框或组合框中某一项的值
End Type Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long Private Const COLOR_HIGHLIGHT =
Private Const COLOR_HIGHLIGHTTEXT =
Private Const COLOR_WINDOW =
Private Const COLOR_WINDOWTEXT =
Private Const LB_GETTEXT = &H189
Private Const WM_DRAWITEM = &H2B
Private Const GWL_WNDPROC = (-)
Private Const ODS_FOCUS = &H10
Private Const ODT_LISTBOX = Private lPrevWndProc As Long Private Function SubClassedList(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim tItem As DRAWITEMSTRUCT
Dim sBuff As String *
Dim sItem As String
Dim lBack As Long
If Msg = WM_DRAWITEM Then '绘制菜单消息
Call CopyMemory(tItem, ByVal lParam, Len(tItem))
If tItem.CtlType = ODT_LISTBOX Then '只处理控件类型为listbox的控件
Call SendMessage(tItem.hwndItem, LB_GETTEXT, tItem.itemID, ByVal sBuff) '获得具体值
sItem = Left(sBuff, InStr(sBuff, Chr()) - )
If (tItem.itemState And ODS_FOCUS) Then '判断某项是否具有焦点
lBack = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT))
Call FillRect(tItem.hdc, tItem.rcItem, lBack)
Call SetBkColor(tItem.hdc, GetSysColor(COLOR_HIGHLIGHT))
Call SetTextColor(tItem.hdc, GetSysColor(COLOR_HIGHLIGHTTEXT))
TextOut tItem.hdc, tItem.rcItem.Left, tItem.rcItem.Top, ByVal sItem, Len(sItem)
DrawFocusRect tItem.hdc, tItem.rcItem
Else '如果没有焦点,则
lBack = CreateSolidBrush(GetSysColor(COLOR_WINDOW))
Call FillRect(tItem.hdc, tItem.rcItem, lBack)
Call SetBkColor(tItem.hdc, GetSysColor(COLOR_WINDOW))
Call SetTextColor(tItem.hdc, tItem.itemData)
TextOut tItem.hdc, tItem.rcItem.Left, tItem.rcItem.Top, ByVal sItem, Len(sItem)
End If
Call DeleteObject(lBack)
SubClassedList =
Exit Function
End If
End If
SubClassedList = CallWindowProc(lPrevWndProc, hWnd, Msg, wParam, lParam)
End Function Public Sub SubLists(ByVal hWnd As Long)
lPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf SubClassedList)
End Sub Public Sub RemoveSubLists(ByVal hWnd As Long)
Call SetWindowLong(hWnd, GWL_WNDPROC, lPrevWndProc)
End Sub '窗体中 : Private Sub Form_Load()
Dim I As Integer
For I = To
List1.AddItem "Color " & I
List2.AddItem "FDSF"
Next
SubLists hWnd
End Sub Private Sub Form_Unload(Cancel As Integer)
RemoveSubLists hWnd
End Sub '如果你想让list1的第五行的字体颜色为红色,则
List1.itemData() = RGB(, , )
List1.Refresh 'listbox的style设置为checkbox sItem = Left(sBuff, InStr(sBuff, Chr()) - )
'改成Trim(sBuff)即可显示全部中文。
Call SetBkColor(tItem.hdc, GetSysColor(COLOR_WINDOW))
Call SetTextColor(tItem.hdc, tItem.itemData)
'这里是改背景和字体颜色的地方。

ListBox 如何改变某行的字体颜色的更多相关文章

  1. 【JavaScript】轻易改变的背景和字体颜色页面

    JavaScript,点击button改变页面背景和字体颜色,网页有N颜色的变化button.点击不同button,网页字体和背景将被改变为不同的颜色. 非常easy的JavaScript小程序. 一 ...

  2. 在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色

    原文:在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色 在wpf datagrid中,想要根据一个条件来改变datagrid行的背景颜色 例如根据学生的年龄来修改,年龄 ...

  3. 改变input的placeholder字体颜色

    改变input的placeholder字体颜色,注意哦,只是placeholder的字,用户输入的字不可以 input::-webkit-input-placeholder{ coloc:#000; ...

  4. PS1应用之——修改linux终端命令行各字体颜色

    最近在学习linux操作系统(CentOS 6 & CentOS 7).觉得linux终端命令行全部为白色,会经常导致命令与输出内容难以分辨.于是上网找到修改linux终端命令行颜色的方法,发 ...

  5. 修改linux终端命令行各字体颜色

    这里我用的是 CentOS 7.5,觉得linux终端命令行全部为白色,会经常导致命令与输出内容难以分辨.于是上网找到修改linux终端命令行颜色的方法,发现通过定义PS1环境变量即可实现,下面我以r ...

  6. Extjs 改变grid行的背景颜色

    ## Ext grid 改变行背景色 Ext.util.CSS.createStyleSheet('.ts {background:#9a9a9bc2;}');//单独创建css样式 { xtype: ...

  7. Mac 的命令行配置字体颜色

    1.在mac命令行终端输入: ls -al  查看所有隐藏文件,找到.bash_profile vi .bash_profile  编辑文件,贴入以下内容并保存 source .bash_profil ...

  8. 改变textView的个别字体颜色

    Spannable span = new SpannableString(getString(R.string.register_need_to_ageree));//例如:register_need ...

  9. 一个div里有多个a标签,改变a标签的字体颜色方法

    <script type="text/javascript">var all=document.getElementById("big");var ...

随机推荐

  1. [置顶] 学习JDK源码:可进一步优化的代码

    1.参数化类型的构造函数比较啰嗦 new HashMap<String, List<String>>() 如果你调用参数化类的构造函数,那么很不幸,你必须要指定类型参数,即便上 ...

  2. addEventListener和attachEvent以及element.onclick的区别

    addEventListener和attachEvent以及element.onclick的区别 attachEvent是ie添加事件处理程序,接收两个参数,其中事件类型名称要加"on&qu ...

  3. Exchange 2016 创建日程,远程服务器返回错误: (401) 未经授权

    背景:在测试环境中一切正常,使用的是Exchange2013,上生产环境Exchange2016,部署后产生如下错误: Microsoft.Exchange.WebServices.Data.Serv ...

  4. SSH整合之_架构的历史序列图

    只用jsp最原始的架构 jsp+DB的2层架构 jsp+DB+_Entity的2层架构 jsp+DB+_Entity3_+Service的三层架构 jsp+DB+_Entity3_+Service_H ...

  5. 推荐一些C#相关的网站、资源和书籍 (转载自http://www.cnblogs.com/jiangxiaofan/p/3808316.html)

    推荐一些C#相关的网站.资源和书籍 (转载自http://blog.csdn.net/chinacsharper/article/details/17514923)   一.网站 1.http://m ...

  6. 读取的XML节点中带有冒号怎么办?

    读取的XML节点中带有冒号怎么办? 昨天,编程读取XML的时候,遇上了类似下面的一段XML <a:root xmlns:a="http://ww.abc.com/"> ...

  7. flask 真是太棒啦,阅读手册后就能做出一个博客了

    真是很好的东西,有很多有益处的东西. 有template引擎, 有flask自己带的g (用来处理访问与数据库打开关闭的) 有flask自己的处理session的功能 自带的jinja2模板引擎也是比 ...

  8. java微信平台,发源码

    最近写了一个微信平台的架构,采用servlet + spring3.0 + hibernate4.1.整体架构由我负责建设,我尽可能的把业务模块分出来.趁着刚搭好的框架,留着这版.代码是大部份都由其他 ...

  9. Android 中单位讲解

    1. dip(dp): device independent pixels(设备独立像素). dp也就是dip.这个和sp基本类似.如果设置表示长度.高度等属性时可以使用dp 或sp.但如果设置字体, ...

  10. IPC之消息队列详解与使用

    一.    概念 消息队列就是一个消息的链表.对消息队列有写权限的进程可以向其中按照一定的规则添加新消息:对消息队列有读权限的进程可以从消息队列中读出消息.消息队列是随内核持续的.下面介绍三个概念: ...