简体   繁体   中英

Excel VBA: Updating userform position/size leaves trail

I am fairly familiar with userforms, so I decided to try and get a little fancy and attempted to make a userform grow/shrink and reposition to align center based on a checkbox change event.

The code is working as intended, but there is one issue. When shrinking the userform, the userform leaves a trail of all size increments set during the loop. This makes the program look less "smooth". I've included a screenshot of the issue as well as the relevant code.

I've tried including variations of DoEvents and Application.ScreenUpdating . ScreenUpdating seemed to do nothing, while DoEvents halved the number of trails, but also made the text inside the userform go a bit crazy during execution.

Note: The checkbox is named "MyCheckBox" and the userform is named "ColumnSelect"

Perhaps I'm trying to do too much with excels memory or w/e.. Any help is appreciated though. Thank you!

Private Sub MyCheckBox_Change()

Dim w As Integer

Application.ScreenUpdating = False

If MyCheckBox.Value = True Then
    For w = 425 To 838 Step 7
        ColumnSelect.Width = ColumnSelect.Width + 7
        ColumnSelect.Left = ColumnSelect.Left - 3.5
    Next w
Else
    'DoEvents
    For w = 838 To 425 Step -7
        ColumnSelect.Width = ColumnSelect.Width - 7
        ColumnSelect.Left = ColumnSelect.Left + 3.5
    Next w
End If
Application.ScreenUpdating = True
End Sub

在此处输入图片说明

I have tested the file on my home (gaming) of, which is much more powerful than the laptop/monitor setup I used when posing the question. There was no visible trail when resizing the user form, so it seems user ASH was correct in his assumption that the issue involved the PC/monitor rather than the code.

If you want credit for the answer I will be happy to give it to you, just submit your own. Otherwise I'll mark this as answerws. Thanks for your help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM