Form Textbox Problem


B

Bruin

I have an inherited form which has some textboxes on it.
After I load my data into the textboxes I try to click in
the textboxes to edit the data. When I click the data I
am only able to put the cursor at the beginning of the
text box regardless of where I click. I am also unable
to select text with the mouse. if I put the focus on
another form and return to the form the textboxes work as
they should. Has anybody had this problem and if so have
they found a solution?
thanks,
Bruin
 
Ad

Advertisements

B

Bruin

ok I have a better description of the problem(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.

Control Library Project Code:



<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
</code>

Windows Application Project Code
<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

</code>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top