Weird problem with Dynamically loaded forms. (vb.net 2003)

Started by
3 comments, last by ZenDarva 16 years, 10 months ago
I'm using Lua and xml to dynamically create forms inside a mdiparent. Everything works beautifully. Except one little oddity. After I create my first dynamic form I lose the ability to bring a form to the front by clicking on it anywhere. It only works if I click on the title bar. I've checked, and I'm pretty sure the lua isn't the problem, as I've tried creating the form directly with the vb.net calls I created for the purpose. I haven't the faintest clue how this could be happening, I don't even know how I would do it intentionally if I *wanted* to, so I have no clue how to debug it. If anyone can give me a clue, it would be very appreciated. I'll include the code that creates the actual window, just incase it helps. It's long and repetative though, just a warning.

    Public Sub New(ByVal Def As clsWindowDef)
        SetupDef(Def)
    End Sub

    Private Sub clsWindowDisp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = mForm
    End Sub

    Private Sub SetupDef(ByVal def As clsWindowDef)
        myDef = def
        Me.Width = def.Width
        Me.Height = def.Height
        Me.Text = def.Title
        Me.Name = def.Title

        Dim Tab As clsCtrlTabDef
        Dim text As clsCtrlTextDef
        Dim int As clsCtrlIntegerDef
        Dim btn As clsCtrlButtonDef
        Dim TB As clsCtrlTextBoxDef
        Dim lst As clsCtrlListBoxDef
        Dim line As clsCtrlLineDef 'Needed, but handle elsewhere. 

        ' Actual Controls...
        Dim cTabPage As TabPage
        Dim cTabControl As TabControl
        Dim cButton As Button
        Dim cTextBox As TextBox
        Dim cListBox As ListBox

        Dim cLabelName As Label
        Dim cLabelValue As Label


        Dim Origonal As clsXMLElement

        If def.Containers.Count > 0 Then
            cTabControl = New TabControl
            cTabControl.Width = Me.Width
            cTabControl.Height = Me.Height
            Me.Controls.Add(cTabControl)
            For Each Origonal In def.Containers
                Select Case Origonal.Type 'i know we only have one right now... but later....
                    Case GML.enumCtrlType.TAB
                        Tab = Origonal
                        cTabPage = New TabPage
                        cTabPage.Text = Tab.Name
                        cTabPage.Name = Tab.Name
                        cTabControl.Controls.Add(cTabPage)
                        cControlCollection.Add(cTabControl, Tab.Name)
                End Select
            Next
        End If
        For Each Origonal In def.Elements
            Select Case Origonal.Type
                Case GML.enumCtrlType.BUTTON
                    btn = Origonal
                    cButton = New Button
                    cButton.Name = btn.Name
                    cButton.Text = btn.Text
                    cButton.Width = btn.Width
                    cButton.Height = btn.Height
                    cButton.Location = New Point(btn.PosX, btn.PosY)
                    If Not cTabControl Is Nothing Then
                        If btn.Tab Is Nothing Then
                            cTabPage = cTabControl.Controls(0)
                            cTabPage.Controls().Add(cButton)
                        Else
                            For Each cTabPage In cTabControl.Controls
                                If cTabPage.Name = btn.Tab.Name Then
                                    cTabPage.Controls.Add(cButton)
                                    Exit For
                                End If
                            Next
                        End If
                    Else
                        Me.Controls.Add(cButton)

                    End If
                    cControlCollection.Add(cButton, cButton.Name)

                Case GML.enumCtrlType.LISTBOX
                    lst = Origonal
                    cListBox = New ListBox
                    cListBox.Name = lst.Name
                    cListBox.Width = lst.Width
                    cListBox.Height = lst.Height
                    cListBox.Location = New Point(lst.PosX, lst.PosY)
                    If Not cTabControl Is Nothing Then
                        If lst.Tab Is Nothing Then
                            cTabPage = cTabControl.Controls(0)
                            cTabPage.Controls().Add(cListBox)
                        Else
                            For Each cTabPage In cTabControl.Controls
                                If cTabPage.Name = lst.Tab.Name Then
                                    cTabPage.Controls.Add(cListBox)
                                    Exit For
                                End If
                            Next
                        End If
                    Else
                        Me.Controls.Add(cListBox)

                    End If
                    cControlCollection.Add(cListBox, cListBox.Name)

                Case GML.enumCtrlType.TEXT
                    cLabelName = New Label
                    cLabelName.Text = Origonal.Name
                    cLabelName.Location = New Point(Origonal.PosX, Origonal.PosY)
                    cLabelName.Width = Origonal.Width
                    cLabelName.Height = Origonal.Height
                    cLabelName.Name = Origonal.Name

                    cLabelValue = New Label
                    text = Origonal
                    cLabelValue.Text = text.Text
                    cLabelValue.Width = text.ValueWidth
                    cLabelValue.Height = text.ValueHeight
                    cLabelValue.Location = New Point(Origonal.PosX + Origonal.Width, Origonal.PosY)
                    cLabelValue.Name = Origonal.Name


                    If Not cTabControl Is Nothing Then
                        If text.Tab Is Nothing Then
                            cTabPage = cTabControl.Controls(0)
                            cTabPage.Controls().Add(cLabelName)
                            cTabPage.Controls.Add(cLabelValue)
                        Else
                            For Each cTabPage In cTabControl.Controls
                                If cTabPage.Name = text.Tab.Name Then
                                    cTabPage.Controls.Add(cLabelName)
                                    cTabPage.Controls.Add(cLabelValue)
                                    Exit For
                                End If
                            Next
                        End If
                    Else
                        Me.Controls.Add(cLabelName)
                        Me.Controls.Add(cLabelValue)
                    End If
                    cControlCollection.Add(cLabelValue, Origonal.Name)
                Case GML.enumCtrlType.INT
                    cLabelName = New Label
                    cLabelName.Text = Origonal.Name
                    cLabelName.Location = New Point(Origonal.PosX, Origonal.PosY)
                    cLabelName.Width = Origonal.Width
                    cLabelName.Height = Origonal.Height
                    cLabelName.Name = Origonal.Name

                    cLabelValue = New Label
                    int = Origonal
                    cLabelValue.Text = int.Value
                    cLabelValue.Width = int.ValueWidth
                    cLabelValue.Height = int.ValueHeight
                    cLabelValue.Location = New Point(Origonal.PosX + Origonal.Width, Origonal.PosY)
                    cLabelValue.Name = Origonal.Name

                    If Not cTabControl Is Nothing Then
                        If int.Tab Is Nothing Then
                            cTabPage = cTabControl.Controls(0)
                            cTabPage.Controls().Add(cLabelName)
                            cTabPage.Controls.Add(cLabelValue)
                        Else
                            For Each cTabPage In cTabControl.Controls
                                If cTabPage.Name = int.Tab.Name Then
                                    cTabPage.Controls.Add(cLabelName)
                                    cTabPage.Controls.Add(cLabelValue)
                                    Exit For
                                End If
                            Next
                        End If
                    Else
                        Me.Controls.Add(cLabelName)
                        Me.Controls.Add(cLabelValue)
                    End If
                    cControlCollection.Add(cLabelValue, Origonal.Name)

                Case GML.enumCtrlType.TEXTBOX
                    TB = Origonal
                    cTextBox = New TextBox
                    cTextBox.Name = TB.Name
                    cTextBox.Text = TB.Text
                    cTextBox.Location = New Point(TB.PosX, TB.PosY)
                    cTextBox.Width = TB.Width
                    cTextBox.Height = TB.Height
                    cTextBox.Multiline = TB.MultiLine

                    If Not cTabControl Is Nothing Then
                        If TB.Tab Is Nothing Then
                            cTabPage = cTabControl.Controls(0)
                            cTabPage.Controls().Add(cTextBox)
                        Else
                            For Each cTabPage In cTabControl.Controls
                                If cTabPage.Name = TB.Tab.Name Then
                                    cTabPage.Controls.Add(cTextBox)
                                    Exit For
                                End If
                            Next
                        End If
                    Else
                        Me.Controls.Add(cTextBox)
                    End If
                    cControlCollection.Add(cTextBox, TB.Name)
            End Select

        Next

    End Sub


Advertisement
This is a guess, but make sure that events are being processed. This means either using Application.Run, or calling Application.DoEvents each program loop.
There is no program loop, it's purely event driven for now. There is a seprate thread, in a loop, but I've commented out invoking it for now.
Check that mForm isn't null when passed to mdiform. The msdn documentation doesn't explicitly state what happens when you pass null to it. Checking for null before making use of something is always a good idea anyways.

Also, double check that you really aren't invoking that other thread. If that thread is turning on and entering a loop, that can cause it to eat up 100% of your cpu, and would make the form unresponsive.

Otherwise, I'm not sure.

[Edited by - gharen2 on June 11, 2007 3:50:29 AM]
mForm is a global variable, set to the main form upon the main form loading on program start. And as for the second thread, it is definatly not loading. It was the first thing i commented out, for fear of this very thing, as it does use an infinate do/loop loop. Though it's been tested fairly thoroughly, and in the .net 2.0 version of this code it doesn't cause any problems.

The controls are perfectly responsive, the button i've instantiated reacts the second I click it, the cursor switches to the text box I click on immediately, even if it's in a different form... it's just that that form doesn't come to the top, into focus. It's really rather bizarre.

It's rather frustrating trying to downgrade this code to .net 1.1. ::Sighs:: I suppose, if people think it would help, I can post a zip of the whole project, including the LUA code, and the XML documents.

This topic is closed to new replies.

Advertisement