473,698 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# 1.1 Windows Control LostFocus GotFocus question

Hi,

In my .Net 1.1 C# windows form Form1 I have nothing but 2 TextBox controls
on the Form1, the T1 and T2.
I would like to test the sequence of the GotFocus LostFocus things, so I
have the following code on the Form1.

this.T1.LostFoc us +=new EventHandler(T1 _LostFocus);
this.T1 .GotFocus +=new EventHandler(T1 _GotFocus);
this.T2 .LostFocus +=new EventHandler(T2 _LostFocus);
this.T2 .GotFocus += new EventHandler(T2 _GotFocus);

protected void T1_LostFocus(ob ject sender, EventArgs e)
{
MessageBox.Show ("T1_LostFocus" );
}

protected void T1_GotFocus(obj ect sender, EventArgs e)
{
MessageBox.Show ("T1_GotFocus") ;
}

protected void T2_LostFocus(ob ject sender, EventArgs e)
{
MessageBox.Show ("T2_LostFocus" );
}

protected void T2_GotFocus(obj ect sender, EventArgs e)
{
MessageBox.Show ("T2_GotFocus") ;
}

There you go! When I run the Form1, the MessageBox just keep popping out
like an infinitive loop!
I am wondering why that happens! Am I missing anything in testing the
LostFocus GotFocus testing?
Thanks for help.
Jason
Jul 17 '07 #1
2 8058
On Mon, 16 Jul 2007 19:41:28 -0700, Jason Huang
<Ja************ @hotmail.comwro te:
[...]
There you go! When I run the Form1, the MessageBox just keep popping
out
like an infinitive loop!
I am wondering why that happens! Am I missing anything in testing the
LostFocus GotFocus testing?
Every time your MessageBox pops up, it causes the loss of focus for
whatever window and control has focus at the time. Which causes the
MessageBox to pop up again. Etc.

It was suggested to you, in a different thread, that you use the debug
console output to monitor focus changes. IMHO, that was the correct
suggestion, and doing so would avoid having the monitoring itself
interfere with the behavior you're monitoring.

So do that instead.

Pete
Jul 17 '07 #2

Since you have only 2 controls on your form, when one loses focus the other
receives it. This implies that you see the lost focus pop up box for one
control and once you click ok, you see the get focus of the other control.
This sequence repeats over and over. You can also use debug statements to
debug your code and avoid having to click any buttons on pop up windows.

Adrian
"Jason Huang" wrote:
Hi,

In my .Net 1.1 C# windows form Form1 I have nothing but 2 TextBox controls
on the Form1, the T1 and T2.
I would like to test the sequence of the GotFocus LostFocus things, so I
have the following code on the Form1.

this.T1.LostFoc us +=new EventHandler(T1 _LostFocus);
this.T1 .GotFocus +=new EventHandler(T1 _GotFocus);
this.T2 .LostFocus +=new EventHandler(T2 _LostFocus);
this.T2 .GotFocus += new EventHandler(T2 _GotFocus);

protected void T1_LostFocus(ob ject sender, EventArgs e)
{
MessageBox.Show ("T1_LostFocus" );
}

protected void T1_GotFocus(obj ect sender, EventArgs e)
{
MessageBox.Show ("T1_GotFocus") ;
}

protected void T2_LostFocus(ob ject sender, EventArgs e)
{
MessageBox.Show ("T2_LostFocus" );
}

protected void T2_GotFocus(obj ect sender, EventArgs e)
{
MessageBox.Show ("T2_GotFocus") ;
}

There you go! When I run the Form1, the MessageBox just keep popping out
like an infinitive loop!
I am wondering why that happens! Am I missing anything in testing the
LostFocus GotFocus testing?
Thanks for help.
Jason
Jul 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4623
by: Karuppasamy | last post by:
Hi I have created a User Control Containing a Panel and Rich Text Box. The Panel contains some other controls used for formatting the Text entered in the Rich Text Box. My Requirement is that The Panel has to be visible only when the User Control got Focus and the Panel should not be shown to user when the User Control lost its focus.
2
3651
by: MLH | last post by:
A form named frmVehicleEntryForm has a number of textbox controls who's OnGotFocus property setting is an expression... =Change2Green() Change2Green() looks something like this... Dim MyControl As Control Set MyControl = Screen.ActiveControl MyControl.BackColor = 65280 Tabbing from control-to-control is great. Each time I land on
9
1336
by: Brian | last post by:
Hello - I have created a handler as follows that, when fired, will set a boolean value to True/False: AddHandler DirectCast(ctl, TextBox).TextChanged, AddressOf ControlIsDirty Private Sub ControlIsDirty(ByVal sender As System.Object, ByVal e As System.EventArgs)
4
7846
by: Volker Jobst | last post by:
Hi, Is there an event of windows.forms.form which informs me that the active control will be changed before it will be changed? Something like: Private Sub Form_Validating(ByVal sender As Object, ByVal e As ...) Handles Form."EVENT HERE" dim Ok as Boolean = False ... If Not (ok = True) Then
20
2383
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
4
1381
by: Wayne Wengert | last post by:
I have a form that has a cbo set to TabIndex 0 (it is the only item set to tabindex 0). On page Load if I step through the code that cbo LostFocus event fires after other initializations are completed and after the LostFocus event completes, that cbo gets focus and the form opens? Why is that LostFocus event firing? Any hints on how to debug this? Wayne
2
15452
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all events allowing the user control to react to the mouse click. Setting the Enabled property on the label to False comes close, but I don't want the font color to change. Does anyone have an idea how .NET implements the code behind the Enabled...
1
13859
by: moondaddy | last post by:
I have a c# 3.5 wpf app which uses user controls for data entry screens. These data entry screens can be nested inside of each. We can also have several ones open side by side at the same time. All are in a single window. My challenge is to know when a data entry screen (UC) becomes the active control, and when the active user control looses focus and when the next one gets the focus, and so on. When a user control gets or looses...
7
14629
by: Andrus | last post by:
I have UserControls in MDI child forms containing TextBoxes and other controls. When user re-activates form, I need that Control which was last activated is activated again. Currently *first* control is activated always. To reproduce: 1. Run code. 2. Make TextBox2 as current TextBox by selecting its text
0
8683
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
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8873
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...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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
5862
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
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.