vba中自由调整窗体大小方案:

通过添加一个标签(label),通过鼠标在标签上点击并移动来实时修改窗体大小.

先看下效果:

vb.net 窗口如何固定大小 vb6窗体大小设置_最小化

 

 

 具体如下.

1.新建一个窗体.

\

vb.net 窗口如何固定大小 vb6窗体大小设置_ide_02

 2.在窗体的右下角添加一个标签,用来调整大小

vb.net 窗口如何固定大小 vb6窗体大小设置_ide_03

3.设置标签的属性

设置主要属性

标题(Caption): o (字母O)

字体(Font): Marlett 

鼠标指针(MousePointer):8 - fmMousePointerSizeNWSE

 

vb.net 窗口如何固定大小 vb6窗体大小设置_控件_04

4 .添加窗体内代码

1 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
 2                 (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 3 
 4 Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
 5                 (ByVal hWnd As Long, ByVal nIndex As Long) As Long
 6 
 7 Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
 8                 (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
 9 
10 Private Const GWL_STYLE As Long = (-16)
11 Private Const WS_MINIMIZEBOX As Long = &H20000
12 Private Const WS_MAXIMIZEBOX As Long = &H10000
13 
14 Private Sub Label3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
15     
16     '在文本框中显示当前窗体的宽度和高度
17     TextBox1.Value = Me.InsideWidth
18     TextBox2.Value = Me.InsideHeight
19    
20     If Button = 1 Then '鼠标左键
21         
22         '调整窗体大小
23         Me.Width = Me.Width + X
24         Me.Height = Me.Height + Y
25     End If
26 End Sub
27 
28 Private Sub UserForm_Activate()
29 
30     Dim lStyle  As Long
31     Dim hWnd    As Long
32     
33     '为窗体添加最大化和最小化按钮
34     hWnd = FindWindow("ThunderDFrame", Me.Caption)
35     lStyle = GetWindowLong(hWnd, GWL_STYLE)
36     lStyle = lStyle Or WS_MINIMIZEBOX '最小化
37     lStyle = lStyle Or WS_MAXIMIZEBOX '最大化
38     SetWindowLong hWnd, GWL_STYLE, lStyle
39 End Sub
40 
41 Private Sub UserForm_Resize()
42     
43     '重新设定各控件位置
44     Label3.Left = Me.InsideWidth - Label3.Width
45     Label3.Top = Me.InsideHeight - Label3.Height
46 End Sub