Results 1 to 3 of 3

Thread: Setting focus to a textbox (RESOLVED)

  1. #1

    Thread Starter
    Hyperactive Member divined's Avatar
    Join Date
    Aug 2004
    Location
    Thessaloniki, Greece
    Posts
    447

    Setting focus to a textbox (RESOLVED)

    Hello everybody

    I`m trying to do something rather simple, which is trying to set the focus on a textbox from within a Form`s load event. Unfortunately I`m getting a runtime error on that code.

    VB Code:
    1. txtBox.Setfocus = True

    Does anyone have some idea?

    thx, in advance

    George Papadopoulos
    Last edited by divined; Oct 1st, 2004 at 01:37 AM.
    SteadFast!

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You cannot set Focus to a control whose Visible or Enabled properties are False. The Visible property of a control is False until the Form is shown.

    Three ways around this.

    Move the SetFocus code to the Form Activate event.

    Call the Show method in Form Load event and then call SetFocus.

    Set the TabIndex of the text box to 0 and remove the call to SetFocus.

  3. #3

    Thread Starter
    Hyperactive Member divined's Avatar
    Join Date
    Aug 2004
    Location
    Thessaloniki, Greece
    Posts
    447
    ok. thx! I used the Form Activate event handler to set the focus and now it worked!

    George Papadopoulos
    SteadFast!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width