Results 1 to 5 of 5

Thread: [RESOLVED] set focus problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] set focus problem

    I have text1 and text 2.

    Every time the form load, the cursor focus on the text2. I want the cursor focus on the text1 while form load. How Could I do?

    I have set focus on the form load like this

    text1.setfocus but I got the error..

  2. #2
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: set focus problem

    During design time make the TabIndex Property of Text1 to 0.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: set focus problem

    Thank you so much so simple..

  4. #4
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: set focus problem

    No problem. You can now mark this thread resolved. Thanks!

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] set focus problem

    Quote Originally Posted by matrik02
    text1.setfocus but I got the error..
    Just as an FYI.....this is because all of the code in the Form Load will execute before the form becomes visible. When you have this in the Form Load you are asking VB to set focus to a control that is not visible. That will generate an error.

    While setting the tabindex is the easiest way to ensure a control has the focus when a form is loaded, if you must set the focus using code, then place the line of code in the Form_Activate event. This will do the trick without causing an error.

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