| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6992 人关注过本帖
标题:怎么修改VB按钮控件的字体颜色
只看楼主 加入收藏
wzbest
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2005-4-12
收藏
 问题点数:0 回复次数:5 
怎么修改VB按钮控件的字体颜色
谢谢
搜索更多相关主题的帖子: 控件 字体 按钮 颜色 
2006-01-05 19:36
slore
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1108
专家分:0
注 册:2005-7-1
收藏
得分:0 

用label当呗

不然换图片。。。写成彩色字


快上课了……
2006-01-05 20:39
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
收藏
得分:0 
用API,比较麻烦

天津网站建设 http://www./
2006-01-06 00:06
leon2
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:731
专家分:0
注 册:2005-3-18
收藏
得分:0 

建议用 CheckBox 替代。

2006-01-07 16:22
ryu
Rank: 1
等 级:新手上路
帖 子:124
专家分:0
注 册:2006-2-12
收藏
得分:0 

模块:
Option Explicit
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Public 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
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Public Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Public Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const DT_CENTER = &H1
Public Const DT_SINGLELINE = &H20

Public Const BM_SETSTYLE = &HF4

Public Const BS_OWNERDRAW = &HB&

Public Const GWL_STYLE = (-16)
Public Const GWL_WNDPROC = (-4)

Public Const TRANSPARENT = 1

Public Const WM_CTLCOLORSTATIC = &H138
Public Const WM_DRAWITEM = &H2B
Public Const WM_SETFOCUS = &H7

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Type DRAWITEMSTRUCT
CtlType As Long
CtlID As Long
itemID As Long
itemAction As Long
itemState As Long
hwndItem As Long
hdc As Long
rcItem As RECT
itemData As Long
End Type
Global gHW As Long
Global lpPrevWndProc As Long

Private Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim DI As DRAWITEMSTRUCT

Select Case uMsg&
Case WM_DRAWITEM
Call CopyMemory(DI, ByVal lParam, Len(DI))
Call DrawButton(DI)
Case WM_CTLCOLORSTATIC
Call SendMessage(lParam, BM_SETSTYLE, BS_OWNERDRAW, False)
End Select

WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)

End Function

Public Sub Hook()
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub UnHook()
Dim temp As Long
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub

Private Sub DrawButton(DI As DRAWITEMSTRUCT)
Dim hBr As Long, a As Long

If DI.itemState = 16 Or DI.itemState = 0 Then
hBr = CreateSolidBrush(&H0&)
Call FillRect(DI.hdc, DI.rcItem, hBr)
With DI.rcItem
.Left = .Left + 1
.Top = .Top + 1
.Bottom = .Bottom - 1
.Right = .Right - 1
End With
hBr = CreateSolidBrush(&HFFFFFF)
Call FillRect(DI.hdc, DI.rcItem, hBr)
With DI.rcItem
.Left = .Left + 1
.Top = .Top + 1
.Bottom = .Bottom - 1
.Right = .Right - 1
End With
hBr = CreateSolidBrush(&H8000&)
Call FillRect(DI.hdc, DI.rcItem, hBr)
If hBr Then DeleteObject (hBr)
Else
hBr = CreateSolidBrush(&HC0C0C0)
Call FillRect(DI.hdc, DI.rcItem, hBr)
With DI.rcItem
.Left = .Left + 1
.Top = .Top + 1
.Bottom = .Bottom - 1
.Right = .Right - 1
End With
hBr = CreateSolidBrush(&H0&)
Call FillRect(DI.hdc, DI.rcItem, hBr)
With DI.rcItem
.Left = .Left + 1
.Top = .Top + 1
.Bottom = .Bottom - 1
.Right = .Right - 1
End With
hBr = CreateSolidBrush(&H8000&)
Call FillRect(DI.hdc, DI.rcItem, hBr)
If hBr Then DeleteObject (hBr)
End If

DI.rcItem.Top = DI.rcItem.Top + 2
DI.rcItem.Left = DI.rcItem.Left + 2

Call SetBkMode(DI.hdc, TRANSPARENT)
Call SetTextColor(DI.hdc, &HFFFF&)'文字颜色
Call DrawText(DI.hdc, "Command1", 8, DI.rcItem, DT_CENTER Or DT_SINGLELINE)

End Sub
窗体:
Option Explicit

Private Sub Form_Load()
Call SendMessage(Command1.hWnd, BM_SETSTYLE, BS_OWNERDRAW, False)
gHW = Me.hWnd
Hook
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnHook
End Sub


本帖版权归ryu所有.如果引用本帖,请注明帖子的出处和作者;本帖如系引用,其版权归原作者所有.
2006-02-12 21:02
小伟的小伟
Rank: 1
等 级:禁止访问
帖 子:122
专家分:0
注 册:2006-1-25
收藏
得分:0 
楼上方法~我曾经用来拦截消息~
差不多的
2006-02-12 21:08
快速回复:怎么修改VB按钮控件的字体颜色
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050164 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved