How to get focused control name

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

Dear all,
is it possible to get a name of control on the form, which is currently in
focus.
Thanks,
Boni
 
Dim c As Control = Me.ActiveControl

I think you may need to check Me.ActiveControl.Focused too. I confess to
some confusion (10 years worth) regarding these different form/control status
indicators.

Also, If you add controls to a form at runtime rather than in the designer,
then Me.ActiveControl.Name (what the original post asked for) will be
whatever you set it to.
 
A,,
Also, If you add controls to a form at runtime rather than in the
designer,
then Me.ActiveControl.Name (what the original post asked for) will be
whatever you set it to.


You confuse me, what do you mean with that?

Cor
 
I believe this means that when control is created programmatically Name
could be assigned to arbitrary value.
 
Boni said:
is it possible to get a name of control on the form, which is currently in
focus.

\\\
MsgBox(Me.ActiveControl.Name)
///

.... will work for the current form.
 
However, Form.ActiveForm.ActiveControl is bogus. If Form.ActiveForm is
NOHTING, then you have NO way to get the active control on the top most
form. I have seen this issue before... for example if the top most
form as defined by Form.ActiveForm is NOT top of the ZORDER, aka., a
MsgBox or MessageBox is in front of the Form.ActiveForm is wrong AND if
you reference Form.ActiveForm INSIDE a Form at is TOP-MOST, it is OFTEN
set to NOTHING.
 
Dachshund,

You can be right, the same is when your computer is not running.

However, in my idea was Herfried giving a hint where to look for a solution
for this problem.

Just my thought,

Cor
 
To consistently get a valid form... I had to use GetActiveWindow() and
find the matching Window HANDLE from GetActiveWIndow() to a Form native
handle. Not pretty but worked for what I needed.
 

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

Back
Top