473,405 Members | 2,310 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,405 software developers and data experts.

MDI Child Wrong Event Firing

Environment
---------------
Visual Studio.NET 2003 Version 7.1.3088
..NET Framework 1.1 Version 1.1.4322 SP1
XP Professional 5.1.2600 SP2 Build 2600

Problem Description
-----------------------

I have an mdi parent form.
When it opens it creates 2 identical mdi child forms.
The mdi child form contains a textbox and a button.

In the keydown event of the textbox I trap the enter key and display the
contents of the textbox.
In the button click event I display a message box "Click".

When the application runs the 2 child forms are created and the second child
form has focus.
Using the mouse set focus on the textbox and press enter. The message is
displayed as expected.

Now use the mouse to set focus on the first child forms textbox and press
enter.
This time the button click event fires !!

Next set focus on child 2 textbox and press enter - this again works ok.
Finally return to child1 and press enter in the textbox - this now works and
displays the correct message.
If you take the button off the child form the problem doesn't occurr. Also
when both textboxes are working correctly it breaks again if you click the
button, select the other child form and then return to the original child
form.

Looks like a bug to me but I would be interested to know if anyone else has
experienced this problem or know how to prevent it from hapenning ?
--------------------------------------------------------------------
Source Code
--------------------------------------------------------------------
MDI Parent Form
--------------------------------------------------------------------

Public Class frmMain
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(718, 350)
Me.IsMdiContainer = True
Me.Name = "frmMain"
Me.Text = "frmMain"

End Sub

#End Region

Private Sub frmMain_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Create 2 child forms at startup...
Dim frm1 As New frmChild
With frm1
.MdiParent = Me
.TextBox1.Text = "CHILD1"
.Show()
End With

Dim frm2 As New frmChild
With frm2
.MdiParent = Me
.TextBox1.Text = "CHILD2"
.Show()
.Left = frm1.Width + 50
.Top = frm1.Top
End With

End Sub
End Class

--------------------------------------------------------------------
MDI Child Form
--------------------------------------------------------------------
Public Class frmChild
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(21, 48)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(9, 12)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'frmChild
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(127, 86)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Name = "frmChild"
Me.Text = "frmChild"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

MsgBox("Click")

End Sub

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

If e.KeyCode = Keys.Enter Then
MsgBox(TextBox1.Text)
End If

End Sub
End Class

Mar 20 '06 #1
2 2135
Hi Lenster ,

could you check whether the textbox taborder in "first child" is the
same as the textbox taborder in "second child" (wiew>taborder). I have
not tried your code but, from what you say, I have the suspect that
"first child" might have order 0 on the button while the other on the
textbox. Could that be?

-tom

Lenster ha scritto:
Environment .... End Class


Mar 20 '06 #2
Both child forms are instances of the same underlying form so they share the
same tab order etc.

"to**************@uniroma1.it" wrote:
Hi Lenster ,

could you check whether the textbox taborder in "first child" is the
same as the textbox taborder in "second child" (wiew>taborder). I have
not tried your code but, from what you say, I have the suspect that
"first child" might have order 0 on the button while the other on the
textbox. Could that be?

-tom

Lenster ha scritto:
Environment

....
End Class


Mar 20 '06 #3

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

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
2
by: Guy Babbitt | last post by:
I have an MDI application that starts an instance of a child form at application start. I have an event handler on a combo box checking for the selected value to change. When the select value...
2
by: Maria | last post by:
Hi Guys (and Gals) Bit of a newbie to C# here and I am having a problem which I am coming across. I need to capture when events are raised in child objects within a collection and raise them...
3
by: Arulraja | last post by:
Hello, I have created 2 custom server controls, The parent custom control contains multiple child custom controls. The Child control has a button on it. If I Click the button control, it...
2
by: Juan Romero | last post by:
Hey guys, I am working on a web custom control that basically draws a table (ASP Table) with a few child controls in the cells. I have a command button inside one of these cells. The problem I...
2
by: glenn | last post by:
Hi folks, Apparently, when you have a child control inside of a DataGrid, the event handler for the control does not work. I want to put a child control (checkbox, dropdownlist, etc.) into my...
12
by: Phil | last post by:
I can check for MdiChildren.Length=0, but which event handler should I put this in to detect when a child window is closed? TIA Phil.
2
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post by:
vs2005, c# Trying to understand why one way works but the other doesnt. I have not tried to create a simpler mdi/child/showdialog app for posting purposes (I think even this would not be so small...
4
by: imajin | last post by:
Hi, I was wondering if you guys can help me sort this out. I've basically got a custom button which inherits from the Button class, and this button is used throughout my forms. The custom button has...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...
0
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...

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.