Mdi Bug - When Focus isn't enough

 
We discovered a problem with Mdi-style Windows.Forms applications with the .NET Framework 1.1 with and without SP 1. The problem causes incorrect handling of keyboard input by MdiClient windows.
 
To reproduce the problem we build a very simple forms application with a toolbar to open client windows. The client window has a text box and some buttons. We wired up a KeyDown handler to the textbox that checks for pressing the enter key while the cursor is in the text box. In the repro example simply shows a MessageBox when you pressed enter. The event handler works fine when you first open a client window.
 
 
 
 
However, when you click on any of the buttons, then open another client window (or change focus to another window in the Mdi Frame) and then put the cursor back into the text box and hit enter, the form will invoke the event handler for the button you clicked before you switched between child windows. It will no longer invoke the KeyPress handler that's hooked up to the textbox, like it did before we switched focus between the two children.
 
 
 
 
 
Trying to determine what's going on, we looked at a number of things. First we looked if it was a matter of the current focus on the form, but the Focused property is set to the TextBox when the handler for the button is executed.
 
Then we checked if the registered event handlers for the textbox were somehow getting messed up, but examining the event handlers with the code below showed that the events were still properly wired up. We also found that the sender object passed to the event handler is indeed the button, therefore we started looking for the problem in other areas.
 
The realized that the form acted as if it’s executing the event handler for the AcceptButton, but both AcceptButton properties, for the MdiChild and the main frame, were set to null.
 
We then concluded that it must be a bug in the Mdi Framework and sent it off to Microsoft. In the meantime, the only workaround we came up with was to add code to every button handler on the form to check the Focused property.
 
private void button2_Click(object sender, System.EventArgs e)
{
if( textBox1.Focused )
{
MessageBox.Show( "You should really call the text box event handler" );
 
}
else
{
MessageBox.Show( "Button 2" );
}
}
 
That workaround gets pretty tedious if you have lots of input controls on the form though. I'll post an update when I get a response from Microsoft.
Published Wednesday, January 26, 2005 12:24 PM by ChristophDotNet
Filed under:

Comments

# re: Mdi Bug - When Focus isn't enough

Wednesday, January 26, 2005 12:20 PM by Yuriy
I tried to understand something very similiar long time ago.

http://groups-beta.google.com/group/microsoft.public.dotnet.framework.windowsforms/browse_thread/thread/8f13c2a4c02eb8c1/ca890535ac8d129f#ca890535ac8d129f

# Christoph has an interesting problem with WinForms.

Wednesday, January 26, 2005 12:33 PM by TrackBack
Christoph has an interesting problem with WinForms.

# re: Mdi Bug - When Focus isn't enough

Wednesday, January 26, 2005 1:31 PM by Christoph
Yuriy,

Thanks for the link. I read through the response, but I am able to reproduce this regardless of what I set the AcceptReturn property to.

# Interesting Finds so far this week

Thursday, January 27, 2005 8:38 PM by TrackBack
Interesting Finds so far this week

# re:Mdi Bug - When Focus isn't enough

Sunday, April 10, 2005 4:05 AM by TrackBack
^_^,Pretty Good!

# re: Mdi Bug - When Focus isn't enough

Wednesday, November 07, 2007 11:59 AM by Joe

I am running into the same issue now.  Did you ever get a response from Microsoft?

# re: Mdi Bug - When Focus isn't enough

Wednesday, April 09, 2008 3:03 PM by vkilz

Nice portal! <a href=" http://free-8-a2.0catch.com/ ">Free graphic organizers</a> sixsp

# re: Mdi Bug - When Focus isn't enough

Monday, November 24, 2008 11:39 PM by gtwox

Great work! <a href="christmas-3.ogk0p3.us/">Christmas 3</a> renmz

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 1:25 AM by chwxk

I like your wishes! <a href="christmas-4.ogk0p3.us/">Christmas 4</a> krwkm

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 2:34 AM by zpgkz

Beautiful portal! <a href="christmas-6.ogk0p3.us/">Christmas 6</a> dglfx

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 5:39 PM by ipwtu

I like this site! <a href="thanksgiving-1.xii6ey.us/">Thanksgiving 1</a> mxnhi

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 6:09 PM by dbmcw

Beautiful work! <a href="thanksgiving-2.xii6ey.us/">Thanksgiving 2</a> ybnmg

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 6:43 PM by uuzjk

Beautiful site! <a href="thanksgiving-3.xii6ey.us/">Thanksgiving 3</a> vdnto

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 7:48 PM by ynkyo

I like this work! <a href="thanksgiving-5.xii6ey.us/">Thanksgiving 5</a> mfczb

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 8:20 PM by mfjny

I like your portal! <a href="thanksgiving-6.xii6ey.us/">Thanksgiving 6</a> djogz

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 8:54 PM by doxgt

Good portal! <a href="thanksgiving-7.xii6ey.us/">Thanksgiving 7</a> dypef

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 9:29 PM by buqpz

I like your work! <a href="thanksgiving-8.xii6ey.us/">Thanksgiving 8</a> xpypv

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 10:05 PM by lhcpb

I like this work! <a href="thanksgiving-9.xii6ey.us/">Thanksgiving 9</a> yuifk

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 10:40 PM by tfzjq

Best site! <a href="thanksgiving-10.xii6ey.us/">Thanksgiving 10</a> mgglw

# re: Mdi Bug - When Focus isn't enough

Tuesday, November 25, 2008 11:51 PM by cxfkx

Good work! <a href="thanksgiving-12.xii6ey.us/">Thanksgiving 12</a> ooceq

# re: Mdi Bug - When Focus isn't enough

Wednesday, November 26, 2008 1:35 AM by qwpav

I like your work! <a href="thanksgiving-15.xii6ey.us/">Thanksgiving 15</a> xdafu

# re: Mdi Bug - When Focus isn't enough

Wednesday, November 26, 2008 2:11 AM by edrdj

Great wishes! <a href="thanksgiving-16.xii6ey.us/">Thanksgiving 16</a> wpzbk

# re: Mdi Bug - When Focus isn't enough

Wednesday, November 26, 2008 2:45 AM by eiipr

Great wishes! <a href="thanksgiving-17.xii6ey.us/">Thanksgiving 17</a> lkefe

# re: Mdi Bug - When Focus isn't enough

Wednesday, November 26, 2008 3:21 AM by uxcvc

Nice work! <a href="thanksgiving-18.xii6ey.us/">Thanksgiving 18</a> cileb

# re: Mdi Bug - When Focus isn't enough

Wednesday, November 26, 2008 11:01 PM by muuvy

I like this site! <a href="thanksgiving-19.w6hfmf.us/">Thanksgiving 19</a> wzyov

# re: Mdi Bug - When Focus isn't enough

Wednesday, November 26, 2008 11:35 PM by rbaet

Good wishes! <a href="thanksgiving-20.w6hfmf.us/">Thanksgiving 20</a> frnnn

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 12:45 AM by acxsr

Great work! <a href="thanksgiving-22.w6hfmf.us/">Thanksgiving 22</a> yulqs

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 1:21 AM by sfkxs

Good work! <a href="thanksgiving-23.w6hfmf.us/">Thanksgiving 23</a> tlrbz

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 2:30 AM by udcss

Good work! <a href="thanksgiving-25.w6hfmf.us/">Thanksgiving 25</a> wzrsn

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 3:40 AM by krijk

Great work! <a href="thanksgiving-27.w6hfmf.us/">Thanksgiving 27</a> ravnt

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 4:16 AM by ossyt

Beautiful wishes! <a href="thanksgiving-28.w6hfmf.us/">Thanksgiving 28</a> vioiv

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 4:50 AM by mxoii

Best wishes! <a href="thanksgiving-29.w6hfmf.us/">Thanksgiving 29</a> siqdt

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 6:00 AM by ikznb

Best work! <a href="thanksgiving-31.w6hfmf.us/">Thanksgiving 31</a> jsrvk

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 6:36 AM by mkizw

Beautiful portal! <a href="thanksgiving-32.w6hfmf.us/">Thanksgiving 32</a> ulksq

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 7:11 AM by owwqv

Beautiful work! <a href="thanksgiving-33.w6hfmf.us/">Thanksgiving 33</a> cukkg

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 7:46 AM by rwgkv

Good work! <a href="thanksgiving-34.w6hfmf.us/">Thanksgiving 34</a> rrpxa

# re: Mdi Bug - When Focus isn't enough

Thursday, November 27, 2008 8:22 AM by vtnvk

Best work! <a href="thanksgiving-35.w6hfmf.us/">Thanksgiving 35</a> gkxmi

# re: Mdi Bug - When Focus isn't enough

Saturday, December 13, 2008 2:32 AM by hjipn

I like this site! 000-fists.2xv3o1.us/ ">Download disturbed 10 aoxwm

# re: Mdi Bug - When Focus isn't enough

Sunday, December 21, 2008 1:27 PM by zgmao

Beautiful site! 000.xfuxn6.us/ ">Download disturbed 10 ujgzk

# re: Mdi Bug - When Focus isn't enough

Wednesday, December 31, 2008 5:10 AM by ppxkh

I like your site! 000-18 dzptm

# re: Mdi Bug - When Focus isn't enough

Wednesday, January 28, 2009 10:10 PM by ymnsb

Good wishes! 000.html ">Download disturbed 10 sqity

# re: Mdi Bug - When Focus isn't enough

Saturday, March 07, 2009 7:53 AM by oiala

Best site! 2 ouvbl

# re: Mdi Bug - When Focus isn't enough

Tuesday, April 14, 2009 12:15 PM by rpcbl

Good work! 000-easter-egg-hunt-spring-festival.b7j45c.us/ ">10 yxiet

# re: Mdi Bug - When Focus isn't enough

Wednesday, April 22, 2009 9:06 PM by aledd

I like this wishes! <a href=" usuarios.lycos.es/.../index.html ">Index</a> foyal

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 10:45 AM by gldwh

Good portal! <a href=" usuarios.lycos.es/forwert ">mapa</a> fibbg

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 11:28 AM by tmina

Good portal! <a href=" usuarios.lycos.es/forwert ">mapa</a> bbvzj

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 12:45 PM by ucybf

Great portal! <a href=" usuarios.lycos.es/forwert ">mapa</a> erngj

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 1:21 PM by obmin

Good portal! <a href=" usuarios.lycos.es/forwert ">mapa</a> qaqno

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 2:36 PM by dammp

Nice portal! <a href=" usuarios.lycos.es/forwert ">mapa</a> ozdqc

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 3:14 PM by ensiw

Nice portal! <a href=" usuarios.lycos.es/forwert ">mapa</a> teiwp

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 3:45 PM by qudwf

Nice work! <a href=" usuarios.lycos.es/forwert ">mapa</a> rcubc

# re: Mdi Bug - When Focus isn't enough

Friday, April 24, 2009 4:17 PM by kklmz

Nice work! <a href=" usuarios.lycos.es/forwert ">mapa</a> cytxf

# re: Mdi Bug - When Focus isn't enough

Sunday, April 26, 2009 12:08 AM by yrxfx

I like this site! <a href=" members.lycos.nl/.../index.html ">Index</a> dbnnj

# re: Mdi Bug - When Focus isn't enough

Friday, June 05, 2009 8:12 AM by sruzt

Good portal! <a href=" nutrition-for-kidney-health.rpf0d3.us ">nutrition for kidney health</a> slkig

Leave a Comment

(required) 
(required) 
(optional)
(required)