Deleguate setfocus method

Posted on 2007-07-20
Last Modified: 2013-12-26

I've a usercontrol on VB6 and I would like to know how to deleguate the setfocus method?

Thanks by advance.
Question by:esohier
    LVL 11

    Expert Comment

    What do you mean by "deleguate" (delegate?)

    Author Comment


    I would like to give the method to the form to make this sample:

    Sub Form _load


    End Sub
    LVL 11

    Accepted Solution

    Oh, I see.  You want a control to have focus when the form is first displayed (but can't do it in the Form_Load() event, since the controls aren't visible during the load event).

    You have two options

    1. In design mode, set the TabIndex for the control to 0.  This will cause the control in question to acquire focus automatically when the form is loaded (no code required).

    2. Although the Form_Load() event is not a valid place to set the focus of a control, you can put the code in the form's paint event (or even the Activate event).  You shoud set up a static variable so it only hits once (and not every time the form is repainted):

    Private Sub Form_Paint()
        Static bSkip As Boolean
        If Not bSkip Then
        End If
    End Sub

    Author Comment

    Very thanks. That Ok.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now