Setting the focus on a control

  • Thread starter Thread starter Michel
  • Start date Start date
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
 
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.
 
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
 
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
 
Back
Top