Setting the focus on a control

M

Michel

Hello,

In VB.NET 2008, a Do ... Loop, I creates sereral new textboxes. How can I
set the focus on one of them.
My code is:

Do
txtTest = new Textbox
With txtTest
..Name = "Name"
..Text = "Text"
End With
Loop Until ...

I want to set the Focus on a particular textbox. On the other hand, when a
textbox has the focus, I want to be able to recognise it, so I can give it
the focus again at a later time.

Can someone help me?

Many thanks,

Michel
 
M

Miro

should work like this:

textbox.focus()

Once a textbox has focus, you could probably set something in the tag
property or create your own arraylist of controls that have had focus.
Add to the arraylist on 'GotFocus' event.
 
O

OmegaSquared

Hello, Michel,

Re: "...when a textbox has the focus, I want to be able to recognise it..."

You could check the Form's ActiveControl property.

Cheers,
Randy
 
J

James Hahn

In order to set the focus for a control or to test if the control has focus
you need to be able to reference the control name. One way to do this is to
create a control array, and use the array index to reference the control.
See here for a procedure to create a control array.

http://msdn.microsoft.com/en-us/library/aa289500(VS.71).aspx
Creating Control Arrays in Visual Basic .NET and Visual C# .NET
 

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

Similar Threads


Top