命令按钮单击计数器以增加用户窗体的大小
Command button click counter to increase size of userform
我构建了一个包含 2 列的用户表单,每列有 10 行文本框。用户输入并保存信息,稍后通过单击“保存”将这些信息粘贴到相应的单元格中。
为了方便起见,默认值 Userform_initialise 设置了特定的测量值,以便在框架的帮助下隐藏当前未使用的行。如果用户认为他需要 5 行,单击按钮五次将编辑这些测量值以增加框架的大小,取消隐藏行。
问题是当用户完成多行、保存用户表单、再次打开它并尝试添加更多行时。用户窗体将初始化显示已完成的行(例如 1-3),但在计数器赶上并开始显示之前,单击“添加行”以添加其他行将需要 3 次空点击(因为 1-3 行已经取消隐藏)自第 4 次点击起的额外行。
截图
Private Sub commandbutton3_Click()
Static Counter As Integer
Counter = Counter + 1
If Counter = 1 Then
If Frame1.Height = 60 Then
UserForm.Height = 174
Frame1.Height = 90
CommandButton1.Top = 110
CommandButton2.Top = 110
commandbutton3.Top = 110
End If
End If
If Counter = 2 Then
If Frame1.Height = 90 Then
UserForm.Height = 204
Frame1.Height = 120
CommandButton1.Top = 140
CommandButton2.Top = 140
commandbutton3.Top = 140
End If
End If
Reset
If Counter = 3 Then
If Frame1.Height = 120 Then
UserForm.Height = 234
Frame1.Height = 150
CommandButton1.Top = 170
CommandButton2.Top = 170
commandbutton3.Top = 170
End If
End If
Reset
If Counter = 4 Then
If Frame1.Height = 150 Then
UserForm.Height = 264
Frame1.Height = 180
CommandButton1.Top = 200
CommandButton2.Top = 200
commandbutton3.Top = 200
End If
End If
If Counter = 5 Then
If Frame1.Height = 180 Then
UserForm.Height = 294
Frame1.Height = 210
CommandButton1.Top = 230
CommandButton2.Top = 230
commandbutton3.Top = 230
End If
End If
If Counter = 6 Then
If Frame1.Height = 210 Then
UserForm.Height = 324
Frame1.Height = 240
CommandButton1.Top = 260
CommandButton2.Top = 260
commandbutton3.Top = 260
End If
End If
If Counter = 7 Then
If Frame1.Height = 240 Then
UserForm.Height = 355
Frame1.Height = 270
CommandButton1.Top = 290
CommandButton2.Top = 290
commandbutton3.Top = 290
End If
End If
If Counter = 8 Then
If Frame1.Height = 270 Then
UserForm.Height = 382
Frame1.Height = 300
CommandButton1.Top = 320
CommandButton2.Top = 320
commandbutton3.Top = 320
End If
End If
If Counter = 9 Then
If Frame1.Height = 300 Then
UserForm.Height = 413
Frame1.Height = 330
CommandButton1.Top = 350
CommandButton2.Top = 350
commandbutton3.Top = 350
End If
End If
If Counter = 10 Then
If Frame1.Height = 330 Then
UserForm.Height = 564
Frame1.Height = 480
CommandButton1.Top = 500
CommandButton2.Top = 500
commandbutton3.Top = 500
End If
End If
If Counter > 10 Then
If Frame1.Height = 480 Then
MsgBox ("You have reached the maximum number of entries!"), vbEINFORMATION, "TRACKER"
End If
End If
根据Counter
的值设置control/formposition/height。
我的数学可能不对,但你明白了:
Private Sub commandbutton3_Click()
Static Counter As Integer, incr As Long
Counter = Counter + 1
incr = (Counter - 1) * 30
UserForm.Height = 174 + incr
Frame1.Height = 60 + incr
CommandButton1.Top = 110 + incr
CommandButton2.Top = CommandButton1.Top
commandbutton3.Top = CommandButton1.Top
If Counter > 10 Then
MsgBox ("You have reached the maximum number of entries!"), vbInformation, "TRACKER"
End If
End If
我构建了一个包含 2 列的用户表单,每列有 10 行文本框。用户输入并保存信息,稍后通过单击“保存”将这些信息粘贴到相应的单元格中。
为了方便起见,默认值 Userform_initialise 设置了特定的测量值,以便在框架的帮助下隐藏当前未使用的行。如果用户认为他需要 5 行,单击按钮五次将编辑这些测量值以增加框架的大小,取消隐藏行。
问题是当用户完成多行、保存用户表单、再次打开它并尝试添加更多行时。用户窗体将初始化显示已完成的行(例如 1-3),但在计数器赶上并开始显示之前,单击“添加行”以添加其他行将需要 3 次空点击(因为 1-3 行已经取消隐藏)自第 4 次点击起的额外行。
截图
Private Sub commandbutton3_Click()
Static Counter As Integer
Counter = Counter + 1
If Counter = 1 Then
If Frame1.Height = 60 Then
UserForm.Height = 174
Frame1.Height = 90
CommandButton1.Top = 110
CommandButton2.Top = 110
commandbutton3.Top = 110
End If
End If
If Counter = 2 Then
If Frame1.Height = 90 Then
UserForm.Height = 204
Frame1.Height = 120
CommandButton1.Top = 140
CommandButton2.Top = 140
commandbutton3.Top = 140
End If
End If
Reset
If Counter = 3 Then
If Frame1.Height = 120 Then
UserForm.Height = 234
Frame1.Height = 150
CommandButton1.Top = 170
CommandButton2.Top = 170
commandbutton3.Top = 170
End If
End If
Reset
If Counter = 4 Then
If Frame1.Height = 150 Then
UserForm.Height = 264
Frame1.Height = 180
CommandButton1.Top = 200
CommandButton2.Top = 200
commandbutton3.Top = 200
End If
End If
If Counter = 5 Then
If Frame1.Height = 180 Then
UserForm.Height = 294
Frame1.Height = 210
CommandButton1.Top = 230
CommandButton2.Top = 230
commandbutton3.Top = 230
End If
End If
If Counter = 6 Then
If Frame1.Height = 210 Then
UserForm.Height = 324
Frame1.Height = 240
CommandButton1.Top = 260
CommandButton2.Top = 260
commandbutton3.Top = 260
End If
End If
If Counter = 7 Then
If Frame1.Height = 240 Then
UserForm.Height = 355
Frame1.Height = 270
CommandButton1.Top = 290
CommandButton2.Top = 290
commandbutton3.Top = 290
End If
End If
If Counter = 8 Then
If Frame1.Height = 270 Then
UserForm.Height = 382
Frame1.Height = 300
CommandButton1.Top = 320
CommandButton2.Top = 320
commandbutton3.Top = 320
End If
End If
If Counter = 9 Then
If Frame1.Height = 300 Then
UserForm.Height = 413
Frame1.Height = 330
CommandButton1.Top = 350
CommandButton2.Top = 350
commandbutton3.Top = 350
End If
End If
If Counter = 10 Then
If Frame1.Height = 330 Then
UserForm.Height = 564
Frame1.Height = 480
CommandButton1.Top = 500
CommandButton2.Top = 500
commandbutton3.Top = 500
End If
End If
If Counter > 10 Then
If Frame1.Height = 480 Then
MsgBox ("You have reached the maximum number of entries!"), vbEINFORMATION, "TRACKER"
End If
End If
根据Counter
的值设置control/formposition/height。
我的数学可能不对,但你明白了:
Private Sub commandbutton3_Click()
Static Counter As Integer, incr As Long
Counter = Counter + 1
incr = (Counter - 1) * 30
UserForm.Height = 174 + incr
Frame1.Height = 60 + incr
CommandButton1.Top = 110 + incr
CommandButton2.Top = CommandButton1.Top
commandbutton3.Top = CommandButton1.Top
If Counter > 10 Then
MsgBox ("You have reached the maximum number of entries!"), vbInformation, "TRACKER"
End If
End If