473,385 Members | 1,341 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,385 software developers and data experts.

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.LostFocus +=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(object sender, EventArgs e)
{
MessageBox.Show("T1_LostFocus");
}

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

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

protected void T2_GotFocus(object 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 8042
On Mon, 16 Jul 2007 19:41:28 -0700, Jason Huang
<Ja************@hotmail.comwrote:
[...]
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.LostFocus +=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(object sender, EventArgs e)
{
MessageBox.Show("T1_LostFocus");
}

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

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

protected void T2_GotFocus(object 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
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...
2
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...
9
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...
4
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...
20
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
4
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...
2
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...
1
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. ...
7
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*...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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...

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.