VBA中如何根据文本长短设置窗口大小

VBA中如何根据文本长短设置窗口大小,第1张

粗调:用鼠标拉列头(如A,B)和行头(如1,2),这个适用已经有内容的表格,调整后可以使行高和列高很好适应现有的内容。

细调:对准列头或行头-右键-选择列宽或行高-直接输入数字即可,这个比较适和还没具体内容的。

自动调整:开始-格式-自动调整行高、列宽,这个办法也只适用有内容的。图解:

在窗体代码中添加如下代码即可

Option Explicit

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 WS_THICKFRAME As Long = &H40000 '(恢复大小)

Private Const WS_MINIMIZEBOX As Long = &H20000 '(最小化)

Private Const WS_MAXIMIZEBOX As Long = &H10000 '(最大化)

Private Sub UserForm_Initialize()

Dim hWndForm As Long

Dim IStyle As Long

hWndForm = FindWindow("ThunderDFrame", Me.Caption)

IStyle = GetWindowLong(hWndForm, GWL_STYLE)

IStyle = IStyle Or WS_THICKFRAME '还原

IStyle = IStyle Or WS_MINIMIZEBOX '最小化

IStyle = IStyle Or WS_MAXIMIZEBOX '最大化

SetWindowLong hWndForm, GWL_STYLE, IStyle

End Sub

这样么:

    Application.Left = 0

    Application.Top = 0

    Application.Width = 1024

    Application.Height = 760


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/7812831.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存