如何使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
控件的使用

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。