把CommandButton的文本靠左显示,同时改变背景颜色的问题

goodnow 2004-02-24 04:38:48
在Command1.style=0 (Standard)时,
用SetCtlToLeft Command1调用下面过程能使Command1的文本靠左显示,
但此时就不能设置Command1的背景颜色;
而当Command1.style=1 (Graphical)时,背景颜色能改变了,可又不能
用SetCtlToLeft Command1使Command1的文本靠左显示了;
请问如何才能同时实现两种功能,谢谢!

Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Const GWL_STYLE = (-16)
Const BS_LEFT As Long = &H100&


Public Sub SetCtlToLeft(ACtl As Control) '把控件的文本显示置为靠左显示
Dim TempLng As Long
TempLng = GetWindowLong(ACtl.hwnd, GWL_STYLE)
TempLng = TempLng Or BS_LEFT
SetWindowLong ACtl.hwnd, GWL_STYLE, TempLng
ACtl.Refresh
End Sub
...全文
73 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧