Create A Controlled DoEvents

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.

See also  Does It Make Sense to Splurge on a Laptop?

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist