By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,637 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,637 IT Pros & Developers. It's quick & easy.

Is it possible to know when TextBox loses focus to which object it

P: n/a
Hi,

Is it possible to know when TextBox loses focus to which object it lost it?
what i mean is when the LostFocus Event occur is it possible to know which
object got the focus instead?

thanks,
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Gidi,

I believe you will need to traverse all the controls to see which one has the Focused property set.

private void textBox_LostFocus(object sender, EventArgs e)
{
foreach(Control c in this.Controls)
{
if(c.Focused)
label1.Text = c.Name;
}
}

Of course, if you got any container controls with child controls inside you will need to do it recursively or, when creating the Form, add all 'focusable' controls to a list of your own.
On Thu, 07 Jul 2005 10:18:04 +0200, Gidi <sh*****@hotmail.com.dontspam> wrote:
Hi,

Is it possible to know when TextBox loses focus to which object it lost it?
what i mean is when the LostFocus Event occur is it possible to know which
object got the focus instead?

thanks,


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2

P: n/a
better would be to use the ActiveControl property of
System.Windows.Forms.Form class.

"Morten Wennevik" <Mo************@hotmail.com> schrieb im Newsbeitrag
news:op.stjcfbvjklbvpo@stone...
Hi Gidi,

I believe you will need to traverse all the controls to see which one has the Focused property set.
private void textBox_LostFocus(object sender, EventArgs e)
{
foreach(Control c in this.Controls)
{
if(c.Focused)
label1.Text = c.Name;
}
}

Of course, if you got any container controls with child controls inside you will need to do it recursively or, when creating the Form, add all
'focusable' controls to a list of your own.

On Thu, 07 Jul 2005 10:18:04 +0200, Gidi <sh*****@hotmail.com.dontspam> wrote:
Hi,

Is it possible to know when TextBox loses focus to which object it lost it? what i mean is when the LostFocus Event occur is it possible to know which object got the focus instead?

thanks,


--
Happy coding!
Morten Wennevik [C# MVP]

Nov 17 '05 #3

P: n/a

Well, the ActiveControl property is good if you use TAB to change between Controls. However, if the user left-clicks on another control, the ActiveControl will not be updated before LostFocus is triggered.

On Thu, 07 Jul 2005 14:48:26 +0200, cody <de********@gmx.de> wrote:
better would be to use the ActiveControl property of
System.Windows.Forms.Form class.

"Morten Wennevik" <Mo************@hotmail.com> schrieb im Newsbeitrag
news:op.stjcfbvjklbvpo@stone...
Hi Gidi,

I believe you will need to traverse all the controls to see which one has

the Focused property set.

private void textBox_LostFocus(object sender, EventArgs e)
{
foreach(Control c in this.Controls)
{
if(c.Focused)
label1.Text = c.Name;
}
}

Of course, if you got any container controls with child controls inside

you will need to do it recursively or, when creating the Form, add all
'focusable' controls to a list of your own.


On Thu, 07 Jul 2005 10:18:04 +0200, Gidi <sh*****@hotmail.com.dontspam>

wrote:
> Hi,
>
> Is it possible to know when TextBox loses focus to which object it lost it? > what i mean is when the LostFocus Event occur is it possible to know which > object got the focus instead?
>
> thanks,
>


--
Happy coding!
Morten Wennevik [C# MVP]



--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.