1

我想知道在 Visual Studio 2010 上删除未使用的控件(更具体地说,计时器)的最佳方法是什么。我通常会去设计器中的控件并从那里删除它,但控件的代码仍然出现在班级形式。删除与控件关联的代码是否也安全?

4

2 回答 2

2

只要您不需要逻辑,那么可以。我假设您的意思是双击控件时生成的处理程序(例如button1_Click())。当您删除控件时,处理程序的链接将被删除,但 Visual Studio 将这些函数保留在您的表单类中,以防您将它们用于其他用途。

于 2013-05-02T18:11:27.523 回答
1

Delete a control through the visual editor, and the auto-generated code that creates the control and associates it with the form will be deleted as well. Code written by you, as well as event handling code generated through double clicking on the control or its events in the properties pane, will remain.

You should delete code that has to do with an non existent control. Any code that contains invalid references will keep you from building your application. Otherwise leftover code is just dead weight.

于 2013-05-02T18:13:51.850 回答