VB.NET equiv to VB 6.0 "SetFocus()"

N

Newsgroups

Q: How many licks DOES it take to get to the center of a Tootsie Pop?

err... on a more serious note:

What is the VB.NET equivalent of the VB 6.0 "control.SetFocus()" event?

Thanks in advance, and I hope the one-liner was non-offensive :)
 
N

Newsgroups

I tried that ... didn't work 8^/ ... am now wondring if the (retail)
controls I am using are the culprit. I'm gong to add a generic Windows
control of the same calibre to the form, and set focus to it, and see if
that fires...

BRB...
 
H

Herfried K. Wagner [MVP]

Newsgroups said:
I tried that ... didn't work 8^/ ... am now wondring if the (retail)
controls I am using are the culprit. I'm gong to add a generic Windows
control of the same calibre to the form, and set focus to it, and see if
that fires...

Make sure the control you are attempting to set the focus to is both enabled
and visible.
 
N

Newsgroups

Two part failure analysis:

Part 1 -- Failed: Added a standard TextBox control to the form (within a
Retail Control that has "Me.Dock = DockStyle.Fill" enabled)

Part 2 -- Failed:
-- Added a generic Form1 to the project
-- Added three (3) generic Textboxes to the generic Form
-- Added TextBox3.focus() to Form1's Load event
-- Added a generic Button to the Retail-Control-based form
-- Added dialog to open Form1
-- Compiled & Ran
-- >>> TextBox1 had the focus.

I am totally baffled with this one.

Any more suggestions greatly appreciated :)
 
H

Herfried K. Wagner [MVP]

Newsgroups said:
Part 1 -- Failed: Added a standard TextBox control to the form (within a
Retail Control that has "Me.Dock = DockStyle.Fill" enabled)

Part 2 -- Failed:
-- Added a generic Form1 to the project
-- Added three (3) generic Textboxes to the generic Form
-- Added TextBox3.focus() to Form1's Load event
-- Added a generic Button to the Retail-Control-based form
-- Added dialog to open Form1
-- Compiled & Ran
-- >>> TextBox1 had the focus.

At the time when the form's 'Load' event handler executes, the textbox is
invisible and thus the focus is not set. Either set the focus after the
form is shown or adjust the tab order of the controls (property 'TabIndex',
'TabStop') in a way that the third textbox has the lowest 'TabIndex'. The
thread referenced below contains some hints on how to implement a 'Shown'
event for a form:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/2943a7b7afa079f8>
 
B

Bart Mermuys

Hi,

Newsgroups said:
Two part failure analysis:

Part 1 -- Failed: Added a standard TextBox control to the form (within a
Retail Control that has "Me.Dock = DockStyle.Fill" enabled)

Part 2 -- Failed:
-- Added a generic Form1 to the project
-- Added three (3) generic Textboxes to the generic Form
-- Added TextBox3.focus() to Form1's Load event
-- Added a generic Button to the Retail-Control-based form
-- Added dialog to open Form1
-- Compiled & Ran
-- >>> TextBox1 had the focus.

I am totally baffled with this one.

Any more suggestions greatly appreciated :)

You can't set focus if the TextBox isn't fully loaded (Form Load), but you
can activate it, the active control should get focused when the form is done
loading. Use Select() instead of Focus() to activate a control:

In Form Load Event:
TextBox3.Select()


HTH,
Greetings
 
N

Newsgroups

Thanks Bart, will try ...



Bart Mermuys said:
Hi,



You can't set focus if the TextBox isn't fully loaded (Form Load), but you
can activate it, the active control should get focused when the form is
done loading. Use Select() instead of Focus() to activate a control:

In Form Load Event:
TextBox3.Select()


HTH,
Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top