我希望新创建的 winform 具有预定义的字体和图标。
我可以通过手动将所有新的 winform 继承到修改后的 winform(具有定义的字体和图标)来做到这一点。
有没有办法自动执行此操作?
请您参考如下方法:
您可以通过修改项目模板来做到这一点。例如,找到通常位于此处的 Form.zip 文件(如果您使用的是 VS 2010):
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Windows Forms\1033
打开 zip 文件,将 form.designer.cs 文件保存到计算机上的临时位置,然后在文本编辑器中打开它。您将看到如下内容:
namespace $rootnamespace$
{
partial class $safeitemrootname$
{
/// <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 Windows Form 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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "$safeitemrootname$";
//****** MAKE YOUR DESIRED CHANGES HERE
}
#endregion
}
}
进行任何必要的更改,例如我在上面添加了注释 //****** MAKE YOUR DESIRED CHANGES HERE 的地方。保存文件,并将其放回 Form.zip 文件。
关闭 Visual Studio 的所有实例,然后通过转到开始 > 所有程序\Microsoft Visual Studio 2010\Visual Studio Tools\Visual Studio 命令提示符 (2010) 运行 VS cmd 提示符
在命令窗口中输入 devenv/installvstemplates 并等待该命令完成。您可以返回到 VS,当您创建一个新的表单项时,它现在应该有您的更改。
