3 Replies - 993 Views - Last Post: 21 December 2012 - 04:07 PM Rate Topic: -----

#1 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 184
  • Joined: 10-March 12

pre-load all project's forms before displaying startup form

Posted 21 December 2012 - 02:53 PM

I have a project that contains a few forms. Each form do a lot of processing in its load event, so when i navigate from one form to another, there is a delay before displaying it, while the code placed inside the load event executes. What i need to know is how could i go about making all the forms start when the startup form of the project starts, but without displaying them? In other words, is there a way to load all the forms in the background, so when i call form2.show() it is already loaded and it only becomes visible? Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: pre-load all project's forms before displaying startup form

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1031
  • View blog
  • Posts: 4,013
  • Joined: 02-July 08

Re: pre-load all project's forms before displaying startup form

Posted 21 December 2012 - 03:24 PM

There is a way. In the startup form initialize each form, but do not show them. Move the code from the load event to it's constructor(Sub New). Then as you open forms the processing is all done. This way you can hide and show then forms as needed and not creating new instances every time you click a button or whatever to navigate to them.

This seems like a hack to me, I would like to hear what the design is - as there may be a better design route all together.
Was This Post Helpful? 1
  • +
  • -

#3 rusoaica  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 184
  • Joined: 10-March 12

Re: pre-load all project's forms before displaying startup form

Posted 21 December 2012 - 03:38 PM

the program is made up of custom controls which can have their properties altered by the user at the run-time (position, size, some custom actions, etc). These customizations are being saved to registry and are loaded in the form load event. For example, if Form2 has a button positioned at the coordinates 0, 0 and the user changes it location to 100, 100, when the program is being restarted, that value is retrieved from the registry and assigned to the button's location in the load event - thus making the button to start at the coordinates set by the user. But because the forms have a lot of controls inside them, there is a lot of processing for each of them (every control has about 20-30 properties that are being loaded from registry at the load time) and the forms show with a big delay. I am using something like this in the load event of each form:

      For Each obj As LCARSTerminalControls.Controls.ArrowControl In Me.Controls.OfType(Of LCARSTerminalControls.Controls.ArrowControl)()
            If regKey.GetValue("ARROWDIRECTION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ArrowDirection = CustomizeModule.ReturnArrowDirection(regKey.GetValue("ARROWDIRECTION_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
                obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
            End If
            If regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                Dim SavedPosition As String = CStr(regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString))
                obj.Size = New Size(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
            End If
            If regKey.GetValue("COLOR_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                CustomizeModule.GetControlColor(obj, Me.Name)
            End If
            If regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Text = CustomizeModule.ControlText(CStr(regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString)))
            End If
            If regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonTextHeight = CStr(regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonTextAlign = CustomizeModule.ReturnTextAlign(CInt(regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString)))
            End If
            If regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Flash = CType(regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString), Boolean)
            End If
            If regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.FlashInterval = CInt(regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Lit = Not CType(regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString), Boolean)
            End If
        Next

        For Each obj As LCARSTerminalControls.Controls.DoublePillControl In Me.Controls.OfType(Of LCARSTerminalControls.Controls.DoublePillControl)()
            If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
                obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
            End If
            If regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                Dim SavedPosition As String = CStr(regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString))
                obj.Size = New Size(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
            End If
            If regKey.GetValue("COLOR_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                CustomizeModule.GetControlColor(obj, Me.Name)
            End If
            If regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Text = CustomizeModule.ControlText(CStr(regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString)))
            End If
            If regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonTextHeight = CStr(regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonTextAlign = CustomizeModule.ReturnTextAlign(CInt(regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString)))
            End If
            If regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Flash = CType(regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString), Boolean)
            End If
            If regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.FlashInterval = CInt(regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Lit = Not CType(regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString), Boolean)
            End If
        Next


        For Each obj As LCARSTerminalControls.Controls.ElbowControl In Me.Controls.OfType(Of LCARSTerminalControls.Controls.ElbowControl)()
            If regKey.GetValue("ELBOWSTYLE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ElbowControlStyle = CustomizeModule.ReturnElbowStyle(regKey.GetValue("ELBOWSTYLE_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("BUTTONHEIGHT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonHeight = CInt(regKey.GetValue("BUTTONHEIGHT_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("BUTTONWIDTH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonWidth = CInt(regKey.GetValue("BUTTONWIDTH_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                Dim SavedPosition As String = CStr(regKey.GetValue("POSITION_" & Me.Name.ToString & obj.Name.ToString))
                obj.Location = New Point(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
            End If
            If regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                Dim SavedPosition As String = CStr(regKey.GetValue("SIZE_" & Me.Name.ToString & obj.Name.ToString))
                obj.Size = New Size(CInt(SavedPosition.ToString.Substring(0, SavedPosition.IndexOf(","))), CInt(SavedPosition.ToString.Substring(SavedPosition.IndexOf(",") + 1)))
            End If
            If regKey.GetValue("COLOR_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                CustomizeModule.GetControlColor(obj, Me.Name)
            End If
            If regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Text = CustomizeModule.ControlText(CStr(regKey.GetValue("TEXT_" & Me.Name.ToString & obj.Name.ToString)))
            End If
            If regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonTextHeight = CStr(regKey.GetValue("TEXTSIZE_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.ButtonTextAlign = CustomizeModule.ReturnTextAlign(CInt(regKey.GetValue("TEXTALIGN_" & Me.Name.ToString & obj.Name.ToString)))
            End If
            If regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Flash = CType(regKey.GetValue("FLASH_" & Me.Name.ToString & obj.Name.ToString), Boolean)
            End If
            If regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.FlashInterval = CInt(regKey.GetValue("FLASHINTERVAL_" & Me.Name.ToString & obj.Name.ToString))
            End If
            If regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString) IsNot Nothing Then
                obj.Lit = Not CType(regKey.GetValue("LIT_" & Me.Name.ToString & obj.Name.ToString), Boolean)
            End If
        Next



and so on, for every control type inside the forms. That is why i need to load them all at a time and have a progress bar displaying the progress of loading process (i already have this part of code working for the load of the startup form, the progress bar is inside the splash screen form. If you need a demonstration of how the program works, you can test it here.
By the way, i am not quite sure what you meant by initializing the forms.
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1031
  • View blog
  • Posts: 4,013
  • Joined: 02-July 08

Re: pre-load all project's forms before displaying startup form

Posted 21 December 2012 - 04:07 PM

I never got into the registry. I have used XML files for that purpose and they are wicked fast and safer if you ask me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1