|
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
|
|
|
|
|
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.
|
|
|
|
|
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?
|
|
|
|
|
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()
InitializeComponent()
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()
System.Windows.Forms.MessageBox.Show("No Boo today")
End Sub
End Class
|
|
|
|
|
Thanks will give it a try.
|
|
|
|
|
Seems to work.
Will start implementation.
Thanks
|
|
|
|
|
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?
|
|
|
|
|
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.
|
|
|
|