473,597 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange Event Behaviour

I posted this last week, so apologies for re-posting but I'm still looking
for a sensible answer, and I'm hoping somone new might be able to cast some
light...
Basically, I have a fairly complicated application which seems to me to be
misbehaving. The following is an attempt to reproduce the error. There are
reasons in the real application why I'm trying to do things the way they are
here, so please no comments on techniques here, UNLESS I'm trying to do
somthing fundamentally wrong (or stupid!)

Anyway, if someone could humour me and try the following:
1) Create a new dotNET project.
2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the form
that should load on application startup).
3) Make frmMainForm an MDI Container Form.
4) Add the following code for MainForm:

private void MainForm_Load(o bject sender, System.EventArg s e)
{
frmForm1 form1 = new frmForm1();
form1.MdiParent = this;
form1.Show();
}

internal void ShowOtherForm()
{
frmForm2 form2 = new frmForm2();
form2.MdiParent = this;
form2.Show();
}

5) Place a button on form1 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
((frmMainForm)t his.MdiParent). ShowOtherForm() ;
}

6) Place a button and a textBox on form2 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
MessageBox.Show ("Button Pressed");
this.SendToBack ();
}

private void textBox1_KeyUp( object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if(e.KeyCode == Keys.Enter)
MessageBox.Show ("Enter Pressed");
}

7) Run the program, you should get as a child form inside MainForm
8) Click the button on form1 and you should get an instance of form2.
9) Click the button on form2 and you should get the 'Button Pressed' message
and Form1 comes to the front.
10) CLOSE Form1
11) Make sure focus is in the textBox on Form2 and press ENTER.
12) Please can someone explain what happens next...?

I would really appreciate it if someone could try this out and give me their
thoughts, because it's driving me crazy. I have this project available as a
zip-file if you can't be bothered with all the typing.

Many, many thanks.

ChrisM
Jun 26 '06 #1
7 1438
It displays a message box that says "Enter Pressed", just as expected. What
result are you getting?

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
I posted this last week, so apologies for re-posting but I'm still looking
for a sensible answer, and I'm hoping somone new might be able to cast some
light...
Basically, I have a fairly complicated application which seems to me to be
misbehaving. The following is an attempt to reproduce the error. There are
reasons in the real application why I'm trying to do things the way they
are here, so please no comments on techniques here, UNLESS I'm trying to
do somthing fundamentally wrong (or stupid!)

Anyway, if someone could humour me and try the following:
1) Create a new dotNET project.
2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the form
that should load on application startup).
3) Make frmMainForm an MDI Container Form.
4) Add the following code for MainForm:

private void MainForm_Load(o bject sender, System.EventArg s e)
{
frmForm1 form1 = new frmForm1();
form1.MdiParent = this;
form1.Show();
}

internal void ShowOtherForm()
{
frmForm2 form2 = new frmForm2();
form2.MdiParent = this;
form2.Show();
}

5) Place a button on form1 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
((frmMainForm)t his.MdiParent). ShowOtherForm() ;
}

6) Place a button and a textBox on form2 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
MessageBox.Show ("Button Pressed");
this.SendToBack ();
}

private void textBox1_KeyUp( object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if(e.KeyCode == Keys.Enter)
MessageBox.Show ("Enter Pressed");
}

7) Run the program, you should get as a child form inside MainForm
8) Click the button on form1 and you should get an instance of form2.
9) Click the button on form2 and you should get the 'Button Pressed'
message and Form1 comes to the front.
10) CLOSE Form1
11) Make sure focus is in the textBox on Form2 and press ENTER.
12) Please can someone explain what happens next...?

I would really appreciate it if someone could try this out and give me
their thoughts, because it's driving me crazy. I have this project
available as a zip-file if you can't be bothered with all the typing.

Many, many thanks.

ChrisM

Jun 26 '06 #2
That's interesting!!
When I do it, I get 'Button Pressed' which is what was confusing me.
What environment are you using? I have VS2003 and Framework 1.1.

Cheers,

Chris.

PS. You did have exactly the setup I described. Just copied the code and
didn't make any assumptions of corrections? The only way to make it go wrong
is exactly the steps I described. Not accusing you of being unable to follow
simple instructions, but confused as to why it works correctly for you and
not for me. Unless you are using Framework 2.0 which might explain a lot...
:-)

C.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:uo******** ******@TK2MSFTN GP04.phx.gbl...
It displays a message box that says "Enter Pressed", just as expected.
What result are you getting?

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
I posted this last week, so apologies for re-posting but I'm still looking
for a sensible answer, and I'm hoping somone new might be able to cast
some light...
Basically, I have a fairly complicated application which seems to me to
be misbehaving. The following is an attempt to reproduce the error. There
are reasons in the real application why I'm trying to do things the way
they are here, so please no comments on techniques here, UNLESS I'm
trying to do somthing fundamentally wrong (or stupid!)

Anyway, if someone could humour me and try the following:
1) Create a new dotNET project.
2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the form
that should load on application startup).
3) Make frmMainForm an MDI Container Form.
4) Add the following code for MainForm:

private void MainForm_Load(o bject sender, System.EventArg s e)
{
frmForm1 form1 = new frmForm1();
form1.MdiParent = this;
form1.Show();
}

internal void ShowOtherForm()
{
frmForm2 form2 = new frmForm2();
form2.MdiParent = this;
form2.Show();
}

5) Place a button on form1 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
((frmMainForm)t his.MdiParent). ShowOtherForm() ;
}

6) Place a button and a textBox on form2 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
MessageBox.Show ("Button Pressed");
this.SendToBack ();
}

private void textBox1_KeyUp( object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if(e.KeyCode == Keys.Enter)
MessageBox.Show ("Enter Pressed");
}

7) Run the program, you should get as a child form inside MainForm
8) Click the button on form1 and you should get an instance of form2.
9) Click the button on form2 and you should get the 'Button Pressed'
message and Form1 comes to the front.
10) CLOSE Form1
11) Make sure focus is in the textBox on Form2 and press ENTER.
12) Please can someone explain what happens next...?

I would really appreciate it if someone could try this out and give me
their thoughts, because it's driving me crazy. I have this project
available as a zip-file if you can't be bothered with all the typing.

Many, many thanks.

ChrisM


Jun 26 '06 #3
I used 2.0 for my initial test. Testing it in 1.1 gives the result you're
seeing though. Strange indeed

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eK******** ******@TK2MSFTN GP03.phx.gbl...
That's interesting!!
When I do it, I get 'Button Pressed' which is what was confusing me.
What environment are you using? I have VS2003 and Framework 1.1.

Cheers,

Chris.

PS. You did have exactly the setup I described. Just copied the code and
didn't make any assumptions of corrections? The only way to make it go
wrong is exactly the steps I described. Not accusing you of being unable
to follow simple instructions, but confused as to why it works correctly
for you and not for me. Unless you are using Framework 2.0 which might
explain a lot... :-)

C.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:uo******** ******@TK2MSFTN GP04.phx.gbl...
It displays a message box that says "Enter Pressed", just as expected.
What result are you getting?

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
I posted this last week, so apologies for re-posting but I'm still
looking for a sensible answer, and I'm hoping somone new might be able to
cast some light...
Basically, I have a fairly complicated application which seems to me to
be misbehaving. The following is an attempt to reproduce the error.
There are reasons in the real application why I'm trying to do things
the way they are here, so please no comments on techniques here, UNLESS
I'm trying to do somthing fundamentally wrong (or stupid!)

Anyway, if someone could humour me and try the following:
1) Create a new dotNET project.
2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the
form that should load on application startup).
3) Make frmMainForm an MDI Container Form.
4) Add the following code for MainForm:

private void MainForm_Load(o bject sender, System.EventArg s e)
{
frmForm1 form1 = new frmForm1();
form1.MdiParent = this;
form1.Show();
}

internal void ShowOtherForm()
{
frmForm2 form2 = new frmForm2();
form2.MdiParent = this;
form2.Show();
}

5) Place a button on form1 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
((frmMainForm)t his.MdiParent). ShowOtherForm() ;
}

6) Place a button and a textBox on form2 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
MessageBox.Show ("Button Pressed");
this.SendToBack ();
}

private void textBox1_KeyUp( object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if(e.KeyCode == Keys.Enter)
MessageBox.Show ("Enter Pressed");
}

7) Run the program, you should get as a child form inside MainForm
8) Click the button on form1 and you should get an instance of form2.
9) Click the button on form2 and you should get the 'Button Pressed'
message and Form1 comes to the front.
10) CLOSE Form1
11) Make sure focus is in the textBox on Form2 and press ENTER.
12) Please can someone explain what happens next...?

I would really appreciate it if someone could try this out and give me
their thoughts, because it's driving me crazy. I have this project
available as a zip-file if you can't be bothered with all the typing.

Many, many thanks.

ChrisM



Jun 26 '06 #4
Glad to hear that you can now see the same problem. I thought for a while I
was going mad...
Any idea what might be going wrong? More importantly, any idea how to stop
it from happening???

;-)

Thanks,

Chris.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
I used 2.0 for my initial test. Testing it in 1.1 gives the result you're
seeing though. Strange indeed

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eK******** ******@TK2MSFTN GP03.phx.gbl...
That's interesting!!
When I do it, I get 'Button Pressed' which is what was confusing me.
What environment are you using? I have VS2003 and Framework 1.1.

Cheers,

Chris.

PS. You did have exactly the setup I described. Just copied the code and
didn't make any assumptions of corrections? The only way to make it go
wrong is exactly the steps I described. Not accusing you of being unable
to follow simple instructions, but confused as to why it works correctly
for you and not for me. Unless you are using Framework 2.0 which might
explain a lot... :-)

C.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:uo******** ******@TK2MSFTN GP04.phx.gbl...
It displays a message box that says "Enter Pressed", just as expected.
What result are you getting?

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
I posted this last week, so apologies for re-posting but I'm still
looking for a sensible answer, and I'm hoping somone new might be able
to cast some light...
Basically, I have a fairly complicated application which seems to me to
be misbehaving. The following is an attempt to reproduce the error.
There are reasons in the real application why I'm trying to do things
the way they are here, so please no comments on techniques here, UNLESS
I'm trying to do somthing fundamentally wrong (or stupid!)

Anyway, if someone could humour me and try the following:
1) Create a new dotNET project.
2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the
form that should load on application startup).
3) Make frmMainForm an MDI Container Form.
4) Add the following code for MainForm:

private void MainForm_Load(o bject sender, System.EventArg s e)
{
frmForm1 form1 = new frmForm1();
form1.MdiParent = this;
form1.Show();
}

internal void ShowOtherForm()
{
frmForm2 form2 = new frmForm2();
form2.MdiParent = this;
form2.Show();
}

5) Place a button on form1 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
((frmMainForm)t his.MdiParent). ShowOtherForm() ;
}

6) Place a button and a textBox on form2 with the following code:
private void button1_Click(o bject sender, System.EventArg s e)
{
MessageBox.Show ("Button Pressed");
this.SendToBack ();
}

private void textBox1_KeyUp( object sender,
System.Windows. Forms.KeyEventA rgs e)
{
if(e.KeyCode == Keys.Enter)
MessageBox.Show ("Enter Pressed");
}

7) Run the program, you should get as a child form inside MainForm
8) Click the button on form1 and you should get an instance of form2.
9) Click the button on form2 and you should get the 'Button Pressed'
message and Form1 comes to the front.
10) CLOSE Form1
11) Make sure focus is in the textBox on Form2 and press ENTER.
12) Please can someone explain what happens next...?

I would really appreciate it if someone could try this out and give me
their thoughts, because it's driving me crazy. I have this project
available as a zip-file if you can't be bothered with all the typing.

Many, many thanks.

ChrisM



Jun 26 '06 #5
It behaves as if the AccepButton property of the form is set to the button,
but it clearly isn't so not sure why that happens. I noticed that it's only
the enter key that triggers the button click event. All other keys gets
routed to the keypress event handler as expected. Looking at the call stack
I noticed that the Form's PropDefaultButt on is set and this is what causes
the button click event handler to be invoked (use Reflector and take a look
in the Form.ProcessDia logKey method). Can't tell you why or where it gets
set though, but that might be worth tracking down.

If you don't already have Reflector you should download it. It's a great
tool to see the code in the framework. You can find it at
http://www.aisto.com/roeder/dotnet/

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eY******** *****@TK2MSFTNG P05.phx.gbl...
Glad to hear that you can now see the same problem. I thought for a while
I was going mad...
Any idea what might be going wrong? More importantly, any idea how to stop
it from happening???

;-)

Thanks,

Chris.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
I used 2.0 for my initial test. Testing it in 1.1 gives the result you're
seeing though. Strange indeed

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eK******** ******@TK2MSFTN GP03.phx.gbl...
That's interesting!!
When I do it, I get 'Button Pressed' which is what was confusing me.
What environment are you using? I have VS2003 and Framework 1.1.

Cheers,

Chris.

PS. You did have exactly the setup I described. Just copied the code and
didn't make any assumptions of corrections? The only way to make it go
wrong is exactly the steps I described. Not accusing you of being unable
to follow simple instructions, but confused as to why it works correctly
for you and not for me. Unless you are using Framework 2.0 which might
explain a lot... :-)

C.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:uo******** ******@TK2MSFTN GP04.phx.gbl...
It displays a message box that says "Enter Pressed", just as expected.
What result are you getting?

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:er******** ******@TK2MSFTN GP04.phx.gbl...
>I posted this last week, so apologies for re-posting but I'm still
>looking for a sensible answer, and I'm hoping somone new might be able
>to cast some light...
>
>
> Basically, I have a fairly complicated application which seems to me
> to be misbehaving. The following is an attempt to reproduce the error.
> There are reasons in the real application why I'm trying to do things
> the way they are here, so please no comments on techniques here,
> UNLESS I'm trying to do somthing fundamentally wrong (or stupid!)
>
> Anyway, if someone could humour me and try the following:
> 1) Create a new dotNET project.
> 2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the
> form that should load on application startup).
> 3) Make frmMainForm an MDI Container Form.
> 4) Add the following code for MainForm:
>
> private void MainForm_Load(o bject sender, System.EventArg s e)
> {
> frmForm1 form1 = new frmForm1();
> form1.MdiParent = this;
> form1.Show();
> }
>
> internal void ShowOtherForm()
> {
> frmForm2 form2 = new frmForm2();
> form2.MdiParent = this;
> form2.Show();
> }
>
> 5) Place a button on form1 with the following code:
> private void button1_Click(o bject sender, System.EventArg s e)
> {
> ((frmMainForm)t his.MdiParent). ShowOtherForm() ;
> }
>
> 6) Place a button and a textBox on form2 with the following code:
> private void button1_Click(o bject sender, System.EventArg s e)
> {
> MessageBox.Show ("Button Pressed");
> this.SendToBack ();
> }
>
> private void textBox1_KeyUp( object sender,
> System.Windows. Forms.KeyEventA rgs e)
> {
> if(e.KeyCode == Keys.Enter)
> MessageBox.Show ("Enter Pressed");
> }
>
> 7) Run the program, you should get as a child form inside MainForm
> 8) Click the button on form1 and you should get an instance of form2.
> 9) Click the button on form2 and you should get the 'Button Pressed'
> message and Form1 comes to the front.
> 10) CLOSE Form1
> 11) Make sure focus is in the textBox on Form2 and press ENTER.
> 12) Please can someone explain what happens next...?
>
> I would really appreciate it if someone could try this out and give me
> their thoughts, because it's driving me crazy. I have this project
> available as a zip-file if you can't be bothered with all the typing.
>
> Many, many thanks.
>
> ChrisM
>



Jun 27 '06 #6
Thanks for your input, Claes, it is much appreciated.

What IS (Prop)DefaultBu tton?? I know what AcceptButton, and CancelButton are
for, but from what I can tell, DefaultButton is an ASP.Net thing, not a
Windows Forms thing?? What could be setting it?

Cheers,

Chris.

PS I didn't have 'Reflector' before, but I do now, and it looks like it
might be useful...

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
It behaves as if the AccepButton property of the form is set to the
button, but it clearly isn't so not sure why that happens. I noticed that
it's only the enter key that triggers the button click event. All other
keys gets routed to the keypress event handler as expected. Looking at the
call stack I noticed that the Form's PropDefaultButt on is set and this is
what causes the button click event handler to be invoked (use Reflector
and take a look in the Form.ProcessDia logKey method). Can't tell you why
or where it gets set though, but that might be worth tracking down.

If you don't already have Reflector you should download it. It's a great
tool to see the code in the framework. You can find it at
http://www.aisto.com/roeder/dotnet/

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eY******** *****@TK2MSFTNG P05.phx.gbl...
Glad to hear that you can now see the same problem. I thought for a while
I was going mad...
Any idea what might be going wrong? More importantly, any idea how to
stop it from happening???

;-)

Thanks,

Chris.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
I used 2.0 for my initial test. Testing it in 1.1 gives the result you're
seeing though. Strange indeed

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eK******** ******@TK2MSFTN GP03.phx.gbl...
That's interesting!!
When I do it, I get 'Button Pressed' which is what was confusing me.
What environment are you using? I have VS2003 and Framework 1.1.

Cheers,

Chris.

PS. You did have exactly the setup I described. Just copied the code
and didn't make any assumptions of corrections? The only way to make it
go wrong is exactly the steps I described. Not accusing you of being
unable to follow simple instructions, but confused as to why it works
correctly for you and not for me. Unless you are using Framework 2.0
which might explain a lot... :-)

C.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:uo******** ******@TK2MSFTN GP04.phx.gbl...
> It displays a message box that says "Enter Pressed", just as expected.
> What result are you getting?
>
> /claes
>
> "ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
> news:er******** ******@TK2MSFTN GP04.phx.gbl...
>>I posted this last week, so apologies for re-posting but I'm still
>>looking for a sensible answer, and I'm hoping somone new might be able
>>to cast some light...
>>
>>
>> Basically, I have a fairly complicated application which seems to me
>> to be misbehaving. The following is an attempt to reproduce the
>> error. There are reasons in the real application why I'm trying to do
>> things the way they are here, so please no comments on techniques
>> here, UNLESS I'm trying to do somthing fundamentally wrong (or
>> stupid!)
>>
>> Anyway, if someone could humour me and try the following:
>> 1) Create a new dotNET project.
>> 2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the
>> form that should load on application startup).
>> 3) Make frmMainForm an MDI Container Form.
>> 4) Add the following code for MainForm:
>>
>> private void MainForm_Load(o bject sender, System.EventArg s e)
>> {
>> frmForm1 form1 = new frmForm1();
>> form1.MdiParent = this;
>> form1.Show();
>> }
>>
>> internal void ShowOtherForm()
>> {
>> frmForm2 form2 = new frmForm2();
>> form2.MdiParent = this;
>> form2.Show();
>> }
>>
>> 5) Place a button on form1 with the following code:
>> private void button1_Click(o bject sender, System.EventArg s e)
>> {
>> ((frmMainForm)t his.MdiParent). ShowOtherForm() ;
>> }
>>
>> 6) Place a button and a textBox on form2 with the following code:
>> private void button1_Click(o bject sender, System.EventArg s e)
>> {
>> MessageBox.Show ("Button Pressed");
>> this.SendToBack ();
>> }
>>
>> private void textBox1_KeyUp( object sender,
>> System.Windows. Forms.KeyEventA rgs e)
>> {
>> if(e.KeyCode == Keys.Enter)
>> MessageBox.Show ("Enter Pressed");
>> }
>>
>> 7) Run the program, you should get as a child form inside MainForm
>> 8) Click the button on form1 and you should get an instance of form2.
>> 9) Click the button on form2 and you should get the 'Button Pressed'
>> message and Form1 comes to the front.
>> 10) CLOSE Form1
>> 11) Make sure focus is in the textBox on Form2 and press ENTER.
>> 12) Please can someone explain what happens next...?
>>
>> I would really appreciate it if someone could try this out and give
>> me their thoughts, because it's driving me crazy. I have this project
>> available as a zip-file if you can't be bothered with all the typing.
>>
>> Many, many thanks.
>>
>> ChrisM
>>
>
>



Jun 27 '06 #7
Hi Claes,

With your invaluable help, I've managed to bodge my way round this problem,
(I hope).
Since, as you pointed out, the problem is stemming from the
'ProcessDialogK ey' code, I've stuck the following code into the Form that is
causing the problem:

protected override bool ProcessDialogKe y(Keys keyData)
{
if (keyData == Keys.Enter && this.ActiveCont rol == textBox1)
return true;
else
return base.ProcessDia logKey (keyData);
}

In other-words, if you've pressed Enter, and you are in the textBox then
don't carry out the usual ProcessDialogKe y code. If you are in any other
control, or pressed any other key then carry on as normal, and pass the call
on up the stack.
Certainly works in my little test App, I'm going to try it in my proper one
now, and see what happens...

Will report back (probably tomorrow)

Thanks once again,

Chris.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
It behaves as if the AccepButton property of the form is set to the
button, but it clearly isn't so not sure why that happens. I noticed that
it's only the enter key that triggers the button click event. All other
keys gets routed to the keypress event handler as expected. Looking at the
call stack I noticed that the Form's PropDefaultButt on is set and this is
what causes the button click event handler to be invoked (use Reflector
and take a look in the Form.ProcessDia logKey method). Can't tell you why
or where it gets set though, but that might be worth tracking down.

If you don't already have Reflector you should download it. It's a great
tool to see the code in the framework. You can find it at
http://www.aisto.com/roeder/dotnet/

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eY******** *****@TK2MSFTNG P05.phx.gbl...
Glad to hear that you can now see the same problem. I thought for a while
I was going mad...
Any idea what might be going wrong? More importantly, any idea how to
stop it from happening???

;-)

Thanks,

Chris.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:O2******** ******@TK2MSFTN GP03.phx.gbl...
I used 2.0 for my initial test. Testing it in 1.1 gives the result you're
seeing though. Strange indeed

/claes

"ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
news:eK******** ******@TK2MSFTN GP03.phx.gbl...
That's interesting!!
When I do it, I get 'Button Pressed' which is what was confusing me.
What environment are you using? I have VS2003 and Framework 1.1.

Cheers,

Chris.

PS. You did have exactly the setup I described. Just copied the code
and didn't make any assumptions of corrections? The only way to make it
go wrong is exactly the steps I described. Not accusing you of being
unable to follow simple instructions, but confused as to why it works
correctly for you and not for me. Unless you are using Framework 2.0
which might explain a lot... :-)

C.

"Claes Bergefall" <lo*****@nospam .nospam> wrote in message
news:uo******** ******@TK2MSFTN GP04.phx.gbl...
> It displays a message box that says "Enter Pressed", just as expected.
> What result are you getting?
>
> /claes
>
> "ChrisM" <ch************ **@suedeyahoo.c om> wrote in message
> news:er******** ******@TK2MSFTN GP04.phx.gbl...
>>I posted this last week, so apologies for re-posting but I'm still
>>looking for a sensible answer, and I'm hoping somone new might be able
>>to cast some light...
>>
>>
>> Basically, I have a fairly complicated application which seems to me
>> to be misbehaving. The following is an attempt to reproduce the
>> error. There are reasons in the real application why I'm trying to do
>> things the way they are here, so please no comments on techniques
>> here, UNLESS I'm trying to do somthing fundamentally wrong (or
>> stupid!)
>>
>> Anyway, if someone could humour me and try the following:
>> 1) Create a new dotNET project.
>> 2) Add 3 Forms: frmMainForm, frmForm1 and frmForm2. (MainForm is the
>> form that should load on application startup).
>> 3) Make frmMainForm an MDI Container Form.
>> 4) Add the following code for MainForm:
>>
>> private void MainForm_Load(o bject sender, System.EventArg s e)
>> {
>> frmForm1 form1 = new frmForm1();
>> form1.MdiParent = this;
>> form1.Show();
>> }
>>
>> internal void ShowOtherForm()
>> {
>> frmForm2 form2 = new frmForm2();
>> form2.MdiParent = this;
>> form2.Show();
>> }
>>
>> 5) Place a button on form1 with the following code:
>> private void button1_Click(o bject sender, System.EventArg s e)
>> {
>> ((frmMainForm)t his.MdiParent). ShowOtherForm() ;
>> }
>>
>> 6) Place a button and a textBox on form2 with the following code:
>> private void button1_Click(o bject sender, System.EventArg s e)
>> {
>> MessageBox.Show ("Button Pressed");
>> this.SendToBack ();
>> }
>>
>> private void textBox1_KeyUp( object sender,
>> System.Windows. Forms.KeyEventA rgs e)
>> {
>> if(e.KeyCode == Keys.Enter)
>> MessageBox.Show ("Enter Pressed");
>> }
>>
>> 7) Run the program, you should get as a child form inside MainForm
>> 8) Click the button on form1 and you should get an instance of form2.
>> 9) Click the button on form2 and you should get the 'Button Pressed'
>> message and Form1 comes to the front.
>> 10) CLOSE Form1
>> 11) Make sure focus is in the textBox on Form2 and press ENTER.
>> 12) Please can someone explain what happens next...?
>>
>> I would really appreciate it if someone could try this out and give
>> me their thoughts, because it's driving me crazy. I have this project
>> available as a zip-file if you can't be bothered with all the typing.
>>
>> Many, many thanks.
>>
>> ChrisM
>>
>
>



Jun 27 '06 #8

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

Similar topics

0
1535
by: Daniel O'Brien | last post by:
Hi - any help with this would be greatly appreicated - it has already had me confused for a good few hours! I am using Visual Studio 2003 and the .NET framework 1.1. I have a C# Windows Service, with my own class extending from ServiceBase in the normal fashion. The service starts a remoting object (WKO and singleton) which many clients can then make calls on. Clients may also register with events on the server such that the server...
3
4863
by: Sebastian C. | last post by:
Hello everybody Since I upgraded my Office XP Professional to SP3 I got strange behaviour. Pieces of code which works for 3 years now are suddenly stop to work properly. I have Office XP Developer (SP3 for Office, SP1 for developer, JET40SP8) on Windows XP Home Edition (SP1). The same behaviour occurs on Windows 98 too.
1
1250
by: Ian | last post by:
Hi, I have noticed some strange behaviour when loading my database. I load a menu form on startup; this form contains a linked image to display. If the project is not then signed, the menu form loads normally, briefly displaying a loading picture progress window before the form appears. However, if I digitally sign the VB project, the image loading progress window flashes repeatedly many times before the menu finally loads.
0
1413
by: theintrepidfox | last post by:
Dear Group I came accross a very annoying behaviour of Visual Studio, giving me six hours of headache till I found the solution. This post is mainly for fellow developers for reference as it took me ages reading through tons of posts till I found an answer. However, I'm also interested why Visual Studio behaves that way. If anyone has a theorie on it please let me know.
7
1175
by: ChrisM | last post by:
I posted this last week, so apologies for re-posting but I'm still looking for a sensible answer, and I'm hoping somone new might be able to cast some light... Basically, I have a fairly complicated application which seems to me to be misbehaving. The following is an attempt to reproduce the error. There are reasons in the real application why I'm trying to do things the way they are here, so please no comments on techniques here,...
5
3101
by: Ian | last post by:
Hi everyone, I have found some bizarre (to me...!) behaviour of the Form_Activate function. I have a form which has a button control used to close the form and a subform with a datasheet view showing a list of jobs from the database. When the main form loses focus and the user clicks the 'Close' button, I kept receiving error 2585 (This action cannot be carried out whilst processing a form or report event). This was tracked down to...
1
1875
by: Asko Telinen | last post by:
Hi all. I ran into quite strange problem concerning the event raising inside FileSystemWatcher Delete event. First, i would like to describe a bit my environment. I have main GUI application, which uses other class libraries. One lib, called Utils.dll contains custom collection implementation. This simple collection just overrides Add and Remove methods to raise
5
1360
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, I have a strange behaviour on the use of delagate. I will try to explain. I have an assembly (Lets call it AssmDB) which contains database function operation like Insert, Delete, Update... Wen one of this operation occurs, I raise an event to any client subscribers. Lets take as an example the Insert function as follow: Step1:
0
7894
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,...
1
8046
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
8262
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
6706
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
5847
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
3937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2409
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
1
1497
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.