如何使frame控件的caption居中显示

     Frame控件是vb中使用得比较频繁的控件之一,它在本质上是个button,因此可以用setwindowlong为其附加或者移除BS_LEFT、BS_RIGHT、BS_CENTER之类的风格,以改变其caption的对齐方式,程序如下:
'窗体上有一个Frame控件
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) 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 Const GWL_STYLE = (-16)
Private Const BS_LEFT = &H100
Private Const BS_RIGHT = &H200
Private Const BS_CENTER = &H300

Private Sub Form_Load()
    Dim style As Long
    Dim mhwnd As Long
    mhwnd = Frame1.hwnd
    style = GetWindowLong(mhwnd, GWL_STYLE)
    'frame控件标签的默认对齐方式是左对齐,所以首先移除左对齐风格(BS_LEFT)
    style = style And Not BS_LEFT
    '附加居中对齐风格(BS_CENTER)
    style = style Or BS_CENTER
    '修改frame1的风格
    Call SetWindowLong(mhwnd, GWL_STYLE, style)
    '强制刷新,正规一点的办法是调用api函数setwindowpos
    '这里我偷懒了
    Frame1.Width = Frame1.Width - 10
    Frame1.Width = Frame1.Width + 10
End Sub

转载于:https://www.cnblogs.com/rainstormmaster/archive/2006/01/14/317229.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值