Click here to Skip to main content
16,005,162 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionShared Member warning Pin
sujanakar21-Mar-06 1:46
sujanakar21-Mar-06 1:46 
AnswerRe: Shared Member warning Pin
CWIZO21-Mar-06 2:41
CWIZO21-Mar-06 2:41 
QuestionCAB file Pin
Paritos21-Mar-06 1:28
Paritos21-Mar-06 1:28 
Questionhi,how to unregistered a downloaded dll Pin
Paritos21-Mar-06 1:23
Paritos21-Mar-06 1:23 
AnswerRe: hi,how to unregistered a downloaded dll Pin
Dave Kreskowiak21-Mar-06 8:05
mveDave Kreskowiak21-Mar-06 8:05 
Questionselect a node from treeview by its text Pin
Osama^20-Mar-06 23:58
Osama^20-Mar-06 23:58 
AnswerRe: select a node from treeview by its text Pin
Dave Kreskowiak21-Mar-06 7:55
mveDave Kreskowiak21-Mar-06 7:55 
QuestionMDI Child Firing Wrong Event Pin
giraffewhisperer20-Mar-06 22:25
giraffewhisperer20-Mar-06 22:25 
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 instances of the same mdi child form.
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.

I have included the source for a test app using VB.NET but the same problem occurs when using C#.

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
AnswerRe: MDI Child Firing Wrong Event Pin
Dave Kreskowiak21-Mar-06 7:43
mveDave Kreskowiak21-Mar-06 7:43 
GeneralRe: MDI Child Firing Wrong Event Pin
giraffewhisperer22-Mar-06 1:57
giraffewhisperer22-Mar-06 1:57 
AnswerRe: MDI Child Firing Wrong Event Pin
Chatura Dilan21-Mar-06 14:15
Chatura Dilan21-Mar-06 14:15 
GeneralRe: MDI Child Firing Wrong Event Pin
giraffewhisperer22-Mar-06 2:39
giraffewhisperer22-Mar-06 2:39 
GeneralRe: MDI Child Firing Wrong Event Pin
giraffewhisperer23-Mar-06 2:21
giraffewhisperer23-Mar-06 2:21 
QuestionHow to open a web page from another web page?? Pin
DreamQuestioner20-Mar-06 19:29
DreamQuestioner20-Mar-06 19:29 
GeneralRe: How to open a web page from another web page?? Pin
CWIZO20-Mar-06 19:46
CWIZO20-Mar-06 19:46 
AnswerRe: How to open a web page from another web page?? Pin
albCode20-Mar-06 20:54
albCode20-Mar-06 20:54 
QuestionXML support in mobile apps Pin
CreepingFeature20-Mar-06 18:55
CreepingFeature20-Mar-06 18:55 
AnswerRe: XML support in mobile apps Pin
CreepingFeature20-Mar-06 21:14
CreepingFeature20-Mar-06 21:14 
Questionbusiness intelligence project type missing in vs 2003 Pin
smita_roy20-Mar-06 18:10
smita_roy20-Mar-06 18:10 
AnswerRe: business intelligence project type missing in vs 2003 Pin
Steve Pullan20-Mar-06 18:51
Steve Pullan20-Mar-06 18:51 
QuestionAccessing Serial and Parallel Port Pin
Ankster20-Mar-06 17:59
Ankster20-Mar-06 17:59 
AnswerRe: Accessing Serial and Parallel Port Pin
Steve Pullan20-Mar-06 18:57
Steve Pullan20-Mar-06 18:57 
QuestionLoading the input files and the output of the previos operations ???? Pin
Ron.S20-Mar-06 17:14
Ron.S20-Mar-06 17:14 
AnswerRe: Loading the input files and the output of the previos operations ???? Pin
Christian Graus20-Mar-06 17:39
protectorChristian Graus20-Mar-06 17:39 
QuestionMemory Usage in Picture box Pin
cylix200020-Mar-06 16:43
cylix200020-Mar-06 16:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.