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
 

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

Newbie 7
Setting Focus to Desired Control on a TabPage 2
Setting focus inside a Panel 6
focus 1
Form Focus 6
Focus Doesn't Work With Splitter Panel 4
Set Focus to textbox on tab control 3
contextmenu 2

Back
Top