Replace the existing control with a custom .NET Winforms class

I have an existing .NET application with many controls already created.

Now I have a new custom control class for buttons - say - (which inherits from "Button"), with additional properties, methods, etc. Compiled perfectly and it appears on my toolbar.

How can I tell VS that I want to REPLACE existing controls with a new one?

I mean, if I open the designer code and manually change the type of control, VS is really unhappy, and the design is broken and will go down with an unpleasant error message.

Is there any way to change the code created by the constructor without breaking the design in VS?

Or is there a way to do this, except manually delete each control and create a new one? This would be a real problem, since all control handlers will be deleted in the form code when I remove the control. How:

handles myControl.Click ... handles myControl.MouseHover ... etc.

Welcome any greetings!

+5
source share
2 answers

The complete procedure is in progress.

Make a backup!

Go to the solution explorer window (Ctrl Alt L is the shortcut) and click the "Show all files" button. Select the form you want to control. Click on the small triangle to display the "designer.vb" file.

Open it.

, . :

Me.ControlToBeReplaced = New System.Windows.Forms.TypeOfControlToReplace()

. :

Friend WithEvents ControlToBeReplaced As System.Windows.Forms.TypeOfControlToReplace

+2

VS " ". , " " ( , ). , - (, ), .

0

All Articles