473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
3 2224
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: (Pete Cresswell) | last post by:
I've got a TreeView on the left of my screen. As the user navigates the tree, I load corresonding detail info into the rest of the screen. Works ok, but when the user clicks on a detail field,...
1
by: (Pete Cresswell) | last post by:
I'm using a subform as a navigation list. On the left side of the screen is a subform containing people's names. The right side of the screen is loaded with information about the...
2
by: Mike | last post by:
Hi, There are some way to know which object (A) create an instance of object (B) in the constructor of object (B)? Thanks.
3
by: - Steve - | last post by:
I have two textboxe's (FirstName & LastName). I have set autopostback on both of those. The problem is if you enter the first name and then tab, it doesn't go to the next textbox. So then you...
3
by: Pieter | last post by:
Hi, I'm making an Outlook (2003) Add-In (VB.NET 2005), with a simple button and a textbox (msoControlEdit). When the user types something in the textbox, and clicks on the button, the text in...
3
by: Greg | last post by:
The LostFocus event of datagrids is fired when the focus is added to a cell. How do you go about detecting it when the control as a whole has lost focus to another control? Slightly confused by...
1
by: jjwhite01 | last post by:
I am working on a web form that contains a Calendar control with an image button that makes the calendar appear and disappear. However, I would like to set the visible property of the Calendar...
2
by: bg_ie | last post by:
Hi, I have a treeview where the user selects a node before editing it. The problem is that when the user clicks on the text box to edit the node, the treeview loses its focus and the node is no...
2
Sl1ver
by: Sl1ver | last post by:
hi im using XtraGrid, the problem i have is that all my functionality is incorporated into the "focusedrowchanged" now what function can i use when there is only 1 row, meaning focused row can't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.