Create A Controlled DoEvents

I needed a way to issue a DoEvents to allow Windows time to redraw controlson a form, but wanted to prevent the user from clicking some other controlwithin my application. I created a tiny form called F_DoEvents with the following properties:

 ControlBox = False MaxButton = False MinButton = FalseBorderStyle = noneSub Form_Load	Left = Width * -1	Top = Height * -1End Sub

This makes the form essentially invisible. The only code in the formis:

 Sub Form_Activate	DoEvents	Me.HideEnd Sub

Now, whenever I want to issue a limited DoEvents, I code:

 F_DoEvents.Show 1

Because the form is displayed modally, the current code is suppressedwhile the F_DoEvents form is “displayed.” This form issues theDoEvents and then hides itself, returning control to the “caller.”I experienced no noticeable degradation in performance. Hiding the formis much faster than unloading it each time. One warning: be sure to terminate your application with an END statementor explicitly unload F_DoEvents when you have finished. Unloading the mainform won’t remove F_DoEvents and the application will appear to hang.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: