我有一个在 InitializeComponent 中调用的覆盖方法。
public class ComponentResourceManager2 : System.ComponentModel.ComponentResourceManager
我的问题是,每次我在 DesignerForm 中更改某些内容时,InitializeComponent 方法都会更改,以便该方法使用系统方法
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager();
例如:我需要这个
private void InitializeComponent()
{
ComponentResourceManager2 resources = new ComponentResourceManager2(typeof(Form1));
this.directDrawViewer1 = new MyOwn.Imaging.Components.DirectDrawViewer();
this.speedButton1 = new MyOwn.Components.SpeedButton();
...
但每次我更改某些内容时,它都会再次出现:
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.directDrawViewer1 = new MyOwn.Imaging.Components.DirectDrawViewer();
this.speedButton1 = new MyOwn.Components.SpeedButton();
我怎样才能使我的方法被InitializeComponent使用,而无需每次更改时都重置?
最佳答案
您不应该更改设计器代码,在调用 InitializeComponent() 后,在 Form 的构造函数中设置您在 InitializeComponent 中设置的内容。每次您在设计器中更改某些内容时,Visual Studio 都会重新生成设计器文件
关于c# - 如何阻止InitializeComponent更改表单设计器代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46937326/