有没有简单点的方法
21 个解决方案
#1
只能用子类
#2
有具体的例子吗
#3
模块
'
'----------------------By 陈锐------------------------------
'如果你要在Internet或BBS上转贴文章,请通知我知道
'Email: blackcat@nease.net develope@163.net
'请参观我的站点 http://www.nease.net/~blackcat
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 = 13
Private Const COLOR_HIGHLIGHTTEXT = 14
Private Const COLOR_WINDOW = 5
Private Const COLOR_WINDOWTEXT = 8
Private Const LB_GETTEXT = &H189
Private Const WM_DRAWITEM = &H2B
Private Const GWL_WNDPROC = (-4)
Private Const ODS_FOCUS = &H10
Private Const ODT_LISTBOX = 2
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 * 255
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(0)) - 1)
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 = 0
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 = 0 To 15
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(4) = RGB(255, 0, 0)
List1.Refresh
'
'----------------------By 陈锐------------------------------
'如果你要在Internet或BBS上转贴文章,请通知我知道
'Email: blackcat@nease.net develope@163.net
'请参观我的站点 http://www.nease.net/~blackcat
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 = 13
Private Const COLOR_HIGHLIGHTTEXT = 14
Private Const COLOR_WINDOW = 5
Private Const COLOR_WINDOWTEXT = 8
Private Const LB_GETTEXT = &H189
Private Const WM_DRAWITEM = &H2B
Private Const GWL_WNDPROC = (-4)
Private Const ODS_FOCUS = &H10
Private Const ODT_LISTBOX = 2
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 * 255
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(0)) - 1)
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 = 0
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 = 0 To 15
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(4) = RGB(255, 0, 0)
List1.Refresh
#4
我把你上面的代码COPY下来,但没有变颜色,帮帮忙,很重要,很急的
#5
List1,List2是不是两个ListBox
#6
你要在适当的地方加上
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
之类的啊
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
之类的啊
#7
Private Sub Form_Load()
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
'List2.AddItem "FDSF"
Next
SubLists hWnd
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
End Sub
这样写有什么问题吗
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
'List2.AddItem "FDSF"
Next
SubLists hWnd
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
End Sub
这样写有什么问题吗
#8
好像要把listbox的style设置为checkbox才可以,我在看看
#9
>>好像要把listbox的style设置为checkbox才可以,我在看看
我这样试了,也不行
麻烦你再帮我看看
我这样试了,也不行
麻烦你再帮我看看
#10
还有人能帮我看看吗
#11
怎么没人啊
#12
跟贴 学习..
#13
牛人帮忙啊,分不够可以加
#14
Private Sub Form_Load()
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
List2.AddItem "FDSF"
Next
List1.itemData(1) = RGB(255, 0, 0)
List1.itemData(2) = RGB(0, 255, 0)
List1.itemData(3) = RGB(0, 0, 255)
SubLists hWnd
End Sub
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
List2.AddItem "FDSF"
Next
List1.itemData(1) = RGB(255, 0, 0)
List1.itemData(2) = RGB(0, 255, 0)
List1.itemData(3) = RGB(0, 0, 255)
SubLists hWnd
End Sub
#15
laviewpbt(人一定要靠自己) 方法有效
收藏了!
收藏了!
#16
有效收藏,是一定要设定成checkbox
#17
收了
#18
测试通过~
恩,不错不错,有学到一招。
恩,不错不错,有学到一招。
#19
By 陈锐
陈锐是VB版的大斑竹,就是这个TechnoFantasy,他写的,不是我。
陈锐是VB版的大斑竹,就是这个TechnoFantasy,他写的,不是我。
#20
为什么这样只能显示三个中文字,英文倒是正常的?还有能不能设置背景色,而不是字体颜色?
#21
sItem = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
改成Trim(sBuff)即可显示全部中文。
Call SetBkColor(tItem.hdc, GetSysColor(COLOR_WINDOW))
Call SetTextColor(tItem.hdc, tItem.itemData)
这里是改背景和字体颜色的地方。
改成Trim(sBuff)即可显示全部中文。
Call SetBkColor(tItem.hdc, GetSysColor(COLOR_WINDOW))
Call SetTextColor(tItem.hdc, tItem.itemData)
这里是改背景和字体颜色的地方。
#1
只能用子类
#2
有具体的例子吗
#3
模块
'
'----------------------By 陈锐------------------------------
'如果你要在Internet或BBS上转贴文章,请通知我知道
'Email: blackcat@nease.net develope@163.net
'请参观我的站点 http://www.nease.net/~blackcat
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 = 13
Private Const COLOR_HIGHLIGHTTEXT = 14
Private Const COLOR_WINDOW = 5
Private Const COLOR_WINDOWTEXT = 8
Private Const LB_GETTEXT = &H189
Private Const WM_DRAWITEM = &H2B
Private Const GWL_WNDPROC = (-4)
Private Const ODS_FOCUS = &H10
Private Const ODT_LISTBOX = 2
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 * 255
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(0)) - 1)
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 = 0
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 = 0 To 15
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(4) = RGB(255, 0, 0)
List1.Refresh
'
'----------------------By 陈锐------------------------------
'如果你要在Internet或BBS上转贴文章,请通知我知道
'Email: blackcat@nease.net develope@163.net
'请参观我的站点 http://www.nease.net/~blackcat
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 = 13
Private Const COLOR_HIGHLIGHTTEXT = 14
Private Const COLOR_WINDOW = 5
Private Const COLOR_WINDOWTEXT = 8
Private Const LB_GETTEXT = &H189
Private Const WM_DRAWITEM = &H2B
Private Const GWL_WNDPROC = (-4)
Private Const ODS_FOCUS = &H10
Private Const ODT_LISTBOX = 2
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 * 255
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(0)) - 1)
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 = 0
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 = 0 To 15
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(4) = RGB(255, 0, 0)
List1.Refresh
#4
我把你上面的代码COPY下来,但没有变颜色,帮帮忙,很重要,很急的
#5
List1,List2是不是两个ListBox
#6
你要在适当的地方加上
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
之类的啊
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
之类的啊
#7
Private Sub Form_Load()
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
'List2.AddItem "FDSF"
Next
SubLists hWnd
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
End Sub
这样写有什么问题吗
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
'List2.AddItem "FDSF"
Next
SubLists hWnd
List1.itemData(4) = RGB(255, 0, 0)
List1.Refresh
End Sub
这样写有什么问题吗
#8
好像要把listbox的style设置为checkbox才可以,我在看看
#9
>>好像要把listbox的style设置为checkbox才可以,我在看看
我这样试了,也不行
麻烦你再帮我看看
我这样试了,也不行
麻烦你再帮我看看
#10
还有人能帮我看看吗
#11
怎么没人啊
#12
跟贴 学习..
#13
牛人帮忙啊,分不够可以加
#14
Private Sub Form_Load()
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
List2.AddItem "FDSF"
Next
List1.itemData(1) = RGB(255, 0, 0)
List1.itemData(2) = RGB(0, 255, 0)
List1.itemData(3) = RGB(0, 0, 255)
SubLists hWnd
End Sub
Dim I As Integer
For I = 0 To 15
List1.AddItem "Color " & I
List2.AddItem "FDSF"
Next
List1.itemData(1) = RGB(255, 0, 0)
List1.itemData(2) = RGB(0, 255, 0)
List1.itemData(3) = RGB(0, 0, 255)
SubLists hWnd
End Sub
#15
laviewpbt(人一定要靠自己) 方法有效
收藏了!
收藏了!
#16
有效收藏,是一定要设定成checkbox
#17
收了
#18
测试通过~
恩,不错不错,有学到一招。
恩,不错不错,有学到一招。
#19
By 陈锐
陈锐是VB版的大斑竹,就是这个TechnoFantasy,他写的,不是我。
陈锐是VB版的大斑竹,就是这个TechnoFantasy,他写的,不是我。
#20
为什么这样只能显示三个中文字,英文倒是正常的?还有能不能设置背景色,而不是字体颜色?
#21
sItem = Left(sBuff, InStr(sBuff, Chr(0)) - 1)
改成Trim(sBuff)即可显示全部中文。
Call SetBkColor(tItem.hdc, GetSysColor(COLOR_WINDOW))
Call SetTextColor(tItem.hdc, tItem.itemData)
这里是改背景和字体颜色的地方。
改成Trim(sBuff)即可显示全部中文。
Call SetBkColor(tItem.hdc, GetSysColor(COLOR_WINDOW))
Call SetTextColor(tItem.hdc, tItem.itemData)
这里是改背景和字体颜色的地方。