Illegal SetFocus Call

Question:
Sometimes when I call

Text1.SetFocus
it returns me an “Illegal function call” error. Any idea why?

Answer:
Normally, if the Form is not visible, you can’t call SetFocus to it. I would imagine you get this error when you call this code from Form_Load. The control is not available at that point in the application load process.

devxblackblue

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