Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to Extend the InitializeComponents to my code in VB2008/2010

How to Extend the InitializeComponents to my code in VB2008/2010

Scheduled Pinned Locked Moved Visual Basic
csharptutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QuickBooksDev
    wrote on last edited by
    #1

    We have many VB2008/2010 programs converted from VB6. They used the VB6 Control Arrays (which I really miss). The VB.Net code uses VB6 compabitity control arrays which works well but hard to maintain if new control arrays are needs. We have begun replacing these with List (of ..) and AddHander's which also works well. What we would like is for our code to populate the list ofs and do the AddHandlers to be done when the InitializeComponent is done. So how can we 'extend' the IntializeComponents to our code or have our code run after the InitializeComponents. Thanks

    L M 2 Replies Last reply
    0
    • Q QuickBooksDev

      We have many VB2008/2010 programs converted from VB6. They used the VB6 Control Arrays (which I really miss). The VB.Net code uses VB6 compabitity control arrays which works well but hard to maintain if new control arrays are needs. We have begun replacing these with List (of ..) and AddHander's which also works well. What we would like is for our code to populate the list ofs and do the AddHandlers to be done when the InitializeComponent is done. So how can we 'extend' the IntializeComponents to our code or have our code run after the InitializeComponents. Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      QuickBooksDev wrote:

      So how can we 'extend' the IntializeComponents to our code or have our code run after the InitializeComponents.

      The "best" way is to not modify the call; it's there for the designer, and anything in there is autogenerated (it will be overwritten, removing your modifications). Add a virtual or abstract method to an empty form, and call it from the constructor. Next, inherit your forms from this new one.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

      Q 1 Reply Last reply
      0
      • L Lost User

        QuickBooksDev wrote:

        So how can we 'extend' the IntializeComponents to our code or have our code run after the InitializeComponents.

        The "best" way is to not modify the call; it's there for the designer, and anything in there is autogenerated (it will be overwritten, removing your modifications). Add a virtual or abstract method to an empty form, and call it from the constructor. Next, inherit your forms from this new one.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

        Q Offline
        Q Offline
        QuickBooksDev
        wrote on last edited by
        #3

        Modify what call. I am looking for a way to invoke our 'DesignerExtensions' automatically. I know not to change the designer. What is a Virtual or abstract method. What constructor? There are none what we have coded. We have several programs with multiple forms that we need to do this on. Can you please give concrete examples?

        L 1 Reply Last reply
        0
        • Q QuickBooksDev

          Modify what call. I am looking for a way to invoke our 'DesignerExtensions' automatically. I know not to change the designer. What is a Virtual or abstract method. What constructor? There are none what we have coded. We have several programs with multiple forms that we need to do this on. Can you please give concrete examples?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          QuickBooksDev wrote:

          Modify what call.

          "InitializeComponents". Don't modify it's contents.

          QuickBooksDev wrote:

          What is a Virtual or abstract method.

          Aw, sorry for using C#-terminology; it's called "Overridable" in VB.NET.

          QuickBooksDev wrote:

          We have several programs with multiple forms that we need to do this on.
          Can you please give concrete examples?

          Take an empty form, and modify it like below;

          Public Class BaseForm
          Sub New()
          ' This call is required by the designer.
          InitializeComponent()

              ' Add any initialization after the InitializeComponent() call.
              InitializeVB6Handlers()
          End Sub
          
          Public Overridable Sub InitializeVB6Handlers()
              System.Windows.Forms.MessageBox.Show("Boo!")
          End Sub
          

          End Class

          Next, change your existing form to Inherit from the BaseForm like below;

          Public Class Form1 : Inherits BaseForm
          End Class

          This would give you a method that's called when the form is constructed (just like InitializeComponents), and give you the option to override it's implementation for a specific form;

          Public Class Form1 : Inherits BaseForm
          Public Overrides Sub InitializeVB6Handlers()
          'MyBase.InitializeVB6Handlers()
          System.Windows.Forms.MessageBox.Show("No Boo today")
          End Sub
          End Class

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

          Q 2 Replies Last reply
          0
          • L Lost User

            QuickBooksDev wrote:

            Modify what call.

            "InitializeComponents". Don't modify it's contents.

            QuickBooksDev wrote:

            What is a Virtual or abstract method.

            Aw, sorry for using C#-terminology; it's called "Overridable" in VB.NET.

            QuickBooksDev wrote:

            We have several programs with multiple forms that we need to do this on.
            Can you please give concrete examples?

            Take an empty form, and modify it like below;

            Public Class BaseForm
            Sub New()
            ' This call is required by the designer.
            InitializeComponent()

                ' Add any initialization after the InitializeComponent() call.
                InitializeVB6Handlers()
            End Sub
            
            Public Overridable Sub InitializeVB6Handlers()
                System.Windows.Forms.MessageBox.Show("Boo!")
            End Sub
            

            End Class

            Next, change your existing form to Inherit from the BaseForm like below;

            Public Class Form1 : Inherits BaseForm
            End Class

            This would give you a method that's called when the form is constructed (just like InitializeComponents), and give you the option to override it's implementation for a specific form;

            Public Class Form1 : Inherits BaseForm
            Public Overrides Sub InitializeVB6Handlers()
            'MyBase.InitializeVB6Handlers()
            System.Windows.Forms.MessageBox.Show("No Boo today")
            End Sub
            End Class

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

            Q Offline
            Q Offline
            QuickBooksDev
            wrote on last edited by
            #5

            Thanks will give it a try.

            1 Reply Last reply
            0
            • Q QuickBooksDev

              We have many VB2008/2010 programs converted from VB6. They used the VB6 Control Arrays (which I really miss). The VB.Net code uses VB6 compabitity control arrays which works well but hard to maintain if new control arrays are needs. We have begun replacing these with List (of ..) and AddHander's which also works well. What we would like is for our code to populate the list ofs and do the AddHandlers to be done when the InitializeComponent is done. So how can we 'extend' the IntializeComponents to our code or have our code run after the InitializeComponents. Thanks

              M Offline
              M Offline
              Mike Meinz
              wrote on last edited by
              #6

              I wonder why you wouldn't just call your customized initialization from within the Load event in your source code for each Windows Form. Doing so, you don't have to touch the Windows Form Designer generated code file (*.Designer.vb). Or am I missing something?

              Q 1 Reply Last reply
              0
              • M Mike Meinz

                I wonder why you wouldn't just call your customized initialization from within the Load event in your source code for each Windows Form. Doing so, you don't have to touch the Windows Form Designer generated code file (*.Designer.vb). Or am I missing something?

                Q Offline
                Q Offline
                QuickBooksDev
                wrote on last edited by
                #7

                We were. But there are times when things need to be checked in various controls before the form is show or brought up. When this occurs the List ofs are not initialized (value of nothing). With the VB6.compatibility for control arrays they were inititized in the designer so no problem. Just looking to make it all work the way it was.

                1 Reply Last reply
                0
                • L Lost User

                  QuickBooksDev wrote:

                  Modify what call.

                  "InitializeComponents". Don't modify it's contents.

                  QuickBooksDev wrote:

                  What is a Virtual or abstract method.

                  Aw, sorry for using C#-terminology; it's called "Overridable" in VB.NET.

                  QuickBooksDev wrote:

                  We have several programs with multiple forms that we need to do this on.
                  Can you please give concrete examples?

                  Take an empty form, and modify it like below;

                  Public Class BaseForm
                  Sub New()
                  ' This call is required by the designer.
                  InitializeComponent()

                      ' Add any initialization after the InitializeComponent() call.
                      InitializeVB6Handlers()
                  End Sub
                  
                  Public Overridable Sub InitializeVB6Handlers()
                      System.Windows.Forms.MessageBox.Show("Boo!")
                  End Sub
                  

                  End Class

                  Next, change your existing form to Inherit from the BaseForm like below;

                  Public Class Form1 : Inherits BaseForm
                  End Class

                  This would give you a method that's called when the form is constructed (just like InitializeComponents), and give you the option to override it's implementation for a specific form;

                  Public Class Form1 : Inherits BaseForm
                  Public Overrides Sub InitializeVB6Handlers()
                  'MyBase.InitializeVB6Handlers()
                  System.Windows.Forms.MessageBox.Show("No Boo today")
                  End Sub
                  End Class

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

                  Q Offline
                  Q Offline
                  QuickBooksDev
                  wrote on last edited by
                  #8

                  Seems to work. Will start implementation. Thanks

                  L 1 Reply Last reply
                  0
                  • Q QuickBooksDev

                    Seems to work. Will start implementation. Thanks

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    You're welcome :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups