I have an existing .NET application with tons of controls already created.
Now I have a new custom control class for - say - buttons (which inherits from "Button"), with extra properties, methods etc. Compiled fine, and it shows in my toolbar.
How can I tell VS that I want to REPLACE existing controls with the new one?
I mean, if I open the designer code and manually change the control's type, VS is really unhappy and the design is broken and down with a nasty error message.
Is there a way to change the designer generated code without breaking the design in VS?
Or Is there a way to do it other than manually delete each control, and create a new one? This would be a real hassle since all control's handlers will be erased in the form's code when I delete the control. Like:
handles myControl.Click ... handles myControl.MouseHover ... etc.
Any tip welcome!
Complete procedure follows.
Make a backup!
Go to solution explorer window (Ctrl Alt L is the shortcut) and click "Show all files" button. Select the form you want to do control replacement. Clic on the small triangle to show the "designer.vb" file.
Open it.
Search for the control instance you want to replace. Check for the occurrences of:
Me.ControlToBeReplaced = New System.Windows.Forms.TypeOfControlToReplace()
Substitute your definition of control. Do the same for every occurrence of:
Friend WithEvents ControlToBeReplaced As System.Windows.Forms.TypeOfControlToReplace
Build your solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With