473,703 Members | 2,542 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 2268
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
3313
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 rectangle. The optimal would be to have it go grey when the control loses focus and return to blue whe...
1
1624
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 change something, they click an "Edit" button that puts
2
1200
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
4194
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 Foundation
3
3641
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
6138
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
1896
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 this in ASP.NET or ASP.NET w/ Javascript?
2
13429
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 = Color.White;
2
3323
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 same as focused row changed
0
8756
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8667
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9251
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9014
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6585
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4429
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.