Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 24th, 2004, 10:58 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default SetFocus on a textbox when form load

Hi,

can anyone tell me how should i setfocus on a textbox immediately after the form loads?

i have put textbox1.focus()††(Vb.net)
but it wont work. I put this code under form_load but the textbox is visible.!
__________________
Snowydust
Reply With Quote
  #2 (permalink)  
Old July 24th, 2004, 01:43 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Either change the tabindex to 0 for the textbox or use this:

Show()
TextBox2.Focus()

You cannot use Focus if the object is disabled or invisible.
Reply With Quote
  #3 (permalink)  
Old July 26th, 2004, 01:05 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

You may put the focus code in the form activate event.
Reply With Quote
  #4 (permalink)  
Old July 26th, 2004, 04:53 AM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The form_load Event do'nt meant that it Visible

Reply With Quote
  #5 (permalink)  
Old July 26th, 2004, 09:56 AM
Friend of Wrox
Points: 3,947, Level: 26
Points: 3,947, Level: 26 Points: 3,947, Level: 26 Points: 3,947, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,150
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

On the ON LOAD event of the form, put this

Me.TextBox1.SetFocus


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote
  #6 (permalink)  
Old July 26th, 2004, 01:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use SetFocus only if the component is visible, but because the form is still invisible during the Load event that code will not work. Put it in any of these evnets: Activate, Paint, Resize. Use a static boolean to do it only once:

public Form_XXX
static bSkip as boolean
if not bSkip then
txt.SetFocus
bSkip=true
endif
Reply With Quote
  #7 (permalink)  
Old July 26th, 2004, 01:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please enlighten me! What's the problem with the two suggestions I made. I might miss something important.

Serrano, I can't make the 'Me'and 'SetFocus' work in VB.NET. Should it?

;)
Reply With Quote
  #8 (permalink)  
Old July 26th, 2004, 04:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your suggestions are correct.
The focus is by default on the component with the lower tabIndex, thus some code must be added in cases where the default is not the right choice.
I did not like your second suggestion (although it works) because I prefer not to call Me.Show in a Load event, in case the form must be loaded but not shown (or shown later)

Marco

Quote:
quote:Originally posted by Birger
 Please enlighten me! What's the problem with the two suggestions I made. I might miss something important.

Serrano, I can't make the 'Me'and 'SetFocus' work in VB.NET. Should it?

;)
Reply With Quote
  #9 (permalink)  
Old August 28th, 2008, 11:13 AM
Registered User
 
Join Date: Aug 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.TabIndex = 0
    End Sub
Reply With Quote
The Following User Says Thank You to Annshul For This Useful Post:
zara (February 10th, 2017)
  #10 (permalink)  
Old February 10th, 2017, 12:43 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2017
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default

This is working, my problem is solved, thanks
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to load multiple Images on the Form? shah123 C# 1 May 20th, 2007 10:28 PM
The MDIChild Form does not load Dhirendra ADO.NET 1 September 23rd, 2006 01:01 PM
Setfocus on textbox rtr1900 Classic ASP Basics 2 July 5th, 2006 06:40 AM
Continuous form / SetFocus help dbartelt Access 5 February 13th, 2006 03:59 PM



All times are GMT -4. The time now is 05:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.