[英]Are custom Winforms control auto generated designer files needed?
Visual Studio创建类似于以下代码:
namespace MyCustomControls
{
partial class MyCustomControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose ( bool disposing )
{
if ( disposing && ( components != null ) )
{
components.Dispose ( );
}
base.Dispose ( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent ( )
{
components = new System.ComponentModel.Container ( );
}
#endregion
}
}
如果要使用设计器图面来布置子控件等(设计器中几乎所有内容) ,则定制设计器文件必不可少。 如果您不这样做(例如,您正在使用自定义绘画,或手动添加子控件),则通常可以非常安全地杀死此文件。
在某些方面,这使得实现Dispose()
等更加容易。
不,不需要从创建新的自定义控件的初始操作生成的代码。 它没有任何功能,实际上可以从应用程序中注释掉。
但是,当您在设计器中使用自定义控件执行任何操作时,非常重要和有用的代码将生成到设计器文件中。 例如创建任何添加的控件,事件处理程序连接以及基本的初始化和布局。 此代码无法删除。
因为您从CustomControl模板开始,所以获得了这些文件,部分类设置和设计图面。
您还可以通过添加“新类”来启动控件,并仅添加您真正需要的内容。 如果您不使用设计器(并且通常不使用CustomControl),那么只会阻碍设计器。
严格来说,我不这么认为,但是那样您将失去创建控件时将获得的任何设计时间收益,而我的猜测是VS将继续尝试重新创建它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.