471,337 Members | 867 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 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 7923
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Karuppasamy | last post: by
9 posts views Thread by Brian | last post: by
4 posts views Thread by Volker Jobst | last post: by
20 posts views Thread by samean | last post: by
4 posts views Thread by Wayne Wengert | last post: by

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.