rainstormmaster的blog
rainstormmaster的blog

     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

posted on 2006-01-14 14:33  学剑学诗两不成  阅读(1831)  评论(0编辑  收藏  举报