替换自定义类。NET的WinForms现有的控制 [英] replace existing control with custom class .NET Winforms

查看:116
本文介绍了替换自定义类。NET的WinForms现有的控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有吨控制现有.NET应用程序已经创建。

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.

我如何告诉VS说我要取代现有的控制与新的?

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

我的意思是,如果我打开设计code和手动更改控件的类型,VS是真的不高兴,设计被打破,下一个讨厌的错误消息。

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.

有没有办法来改变所产生的设计师code,而不会破坏设计VS?

Is there a way to change the designer generated code without breaking the design in VS?

或者是有办法做到比手动删除每个控制它的其他,并创建一个新的?这将是一个真正的麻烦,因为所有的控件的处理程序将在窗体的code被删除时,我删除了控制。像:

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:

处理myControl.Click ...把​​手myControl.MouseHover ...等。

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

任何提示的欢迎!

推荐答案

完整的程序如下:

制作备份!

转到解决方案资源管理器窗口(CTRL + ALT + L是快捷方式),然后单击显示所有文件按钮。 选择你想要做控制置换的形式。 冰冻圈的小三角形,以显示designer.vb文件。

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.

打开它。

搜索您要替换的控件实例。 检查的事件:

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

这篇关于替换自定义类。NET的WinForms现有的控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆