Karlos Garcia
Karlos Garcia

Reputation: 174

set focus inside a user control with VB6

I'm working with VB6. I have several forms and i need open a form. This form have a UserControl. My problem is setfocus in a element of UserControl inside this form.

Sub Form_Activate()
    Ctrl_User.MyTextbox.SetFocus
End Sub

but don't run

How i can do it??

Thanks

Upvotes: 1

Views: 1560

Answers (1)

Richard Kihoro
Richard Kihoro

Reputation: 21

Have you tried this:

Sub Form_Activate()
    Ctrl_User.Enabled = True
    Ctrl_User.MyTextbox.SetFocus
End Sub

Also maybe you may need to review this here as well it may help you more:

If you're authoring a user-drawn control, there won't be any constituent controls on your UserControl. If you don't want your control to be able to receive the focus, set the CanGetFocus property of the UserControl object to False. CanGetFocus is True by default.

If your user-drawn control can receive the focus, the UserControl object will receive GotFocus and LostFocus events when your control receives and loses the focus. A user-drawn control is responsible for drawing its own focus rectangle when it has the focus, as described in "User-Drawn Controls," in this chapter.

This is the only function your UserControl's GotFocus and LostFocus events need to fulfill for a user-drawn control. You don't need to raise GotFocus or LostFocus events for the user of your control, because the container's extender provides these events if the CanGetFocus property is True.

https://msdn.microsoft.com/en-us/library/aa241743(v=vs.60).aspx

Upvotes: 1

Related Questions