By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,047 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

MDI Child Problem

P: n/a
Hi All,
I'm having a problem with MDI child forms when the
reference to the MDI Parent is set in a Control library.
(Sorry for
the long post)

I have an control library assembly which holds all of my
base classes including my base MDI Container form and my
base MDI child form
the mdi container has a singleton which returns an
instance of an mdi container. The load code of the mdi
child form uses the singleton to set its mdi parent.

I also have an application assemlby which defines an mdi
container which is a subclass of the control library mdi
container and mdi child forms which are sub classes of
the control library mdi child form. When the application
starts it creates a new instance of the application MDI
container and sets the singleton in the control library
to it. By doing this all forms will automatically add
themselves as children of the mdi container as well as
inheriting all of the properties of the control library
forms.

My problem is that when I open one child form and then
open a second form from the first form I cannot highlight
text in a textbox on the second form or click to a mid
point in the text using the mouse(highlighting and moving
the cursor with the keyboard work). Once the form has
lost focus and regained focus the textboxes return to
their normal behavior for as long as that form is open.
One additional wrinkle is that the forms only recieve
focus and come to the forground when you click on the
titlebar. if you click in a textbox or anything on the
form the cursor moves to it but the form doesn't recieve
focus and come to the foreground.

If I move the Singleton into the application project
everything works fine, but once I have to start pulling
functionality out of the control library its a slipperly
slope.

When compiling the following code the first form that
opens will appear to work ok, click the button and
experiment with the second form. Does anyone know why
this is happening?
Thanks,
Bruin

'Control Library Project Code:

Public Class BaseMDIContainer
Inherits System.Windows.Forms.Form
Private Shared _MDISingleton As BaseMDIContainer
Public Shared Property MDISingleton() As
BaseMDIContainer
Get
Return _MDISingleton
End Get
Set(ByVal Value As BaseMDIContainer)
_MDISingleton = Value
End Set
End Property

#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()
'
'BaseMDIContainer
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.IsMdiContainer = True
Me.Name = "BaseMDIContainer"
Me.Text = "BaseMDIContainer"

End Sub

#End Region

End Class
Public Class BaseChildForm
Inherits Windows.Forms.Form
Private Sub JasmineForm_Load(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.Load
If Not BaseMDIContainer.MDISingleton Is Nothing
Then
Me.MdiParent = BaseMDIContainer.MDISingleton
End If

End Sub
End Class

'Windows Application Project Code
Public Class InheritedMDI
Inherits ControlLib.BaseMDIContainer

#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()
components = New System.ComponentModel.Container
()
Me.Text = "InheritedMDI"
End Sub

#End Region

Protected Overrides Sub OnLoad(ByVal e As
System.EventArgs)
MyBase.OnLoad(e)
Dim firstform As New InheritedChildForm
firstform.Show()
End Sub
End Class
Module appstart
Public Sub main()
Dim mdi As New InheritedMDI
ControlLib.BaseMDIContainer.MDISingleton = mdi
Application.Run(mdi)
End Sub
End Module

Public Class InheritedChildForm
Inherits ControlLib.BaseChildForm

#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 TextBox1 As
System.Windows.Forms.TextBox
Friend WithEvents Button1 As
System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point
(72, 72)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = "TextBox"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point
(96, 160)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Click Me!"
'
'InheritedChildForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "InheritedChildForm"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim anotherform As New InheritedChildForm
anotherform.Show()
End Sub
End Class


Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.