473,566 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2248
Hi Gidi,

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

private void textBox_LostFoc us(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*****@hotmai l.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.stjcfbv jklbvpo@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_LostFoc us(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*****@hotmai l.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.stjcfbv jklbvpo@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_LostFoc us(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*****@hotmai l.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
3306
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, the TreeView's selection rectangle goes away and the user is left wondering what happened. Seems like there ought TB a way to preserve that...
1
1617
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 currently-selected person. As the user walks the list, the right side of the screen gets reloaded with info about each new name. When the user decides to...
2
1196
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
4181
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 have to click with the mouse on the LastName text box. How can I keep the tabs going where they should? -- Steve Evans Email Services SDSU...
3
3633
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 the textbox should be used. But on the moment that the textbox loses the focus, it loses the text also... Any idea how to get around this problem?
3
6131
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 this! Greg.
1
1890
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 control to false when the control loses focus so that when the user moves to the next field in the form the calendar disappears. Is there anyway to do...
2
13404
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 longer highlighted. To fix this I do something like - void treeView_AfterSelect(object sender, EventArgs e) { selectedNode.BackColor =...
2
3313
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 change or user presses enter or clicks outside of the grid or even directly close it? i tried BeforeLeaveRow aswell and it seems to work exactly the...
0
7666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.