如何正确替换 Form1.Designers.cs 中标签的硬编码字符串?
代替:
this.button1.Text = "TheButton";
this.label1.Text = "TheLabel";
我想写:
this.button1.Text = Resources.ButtonText;
this.label1.Text = Resources.LabelText;
在可视化设计器中更改表单后(添加任何组件并保存)VS 代码生成器将标签文本转回硬编码字符串:
this.button1.Text = Resources.ButtonText;
this.label1.Text = "TheLabel";
有人知道如何解决这个问题吗?
最佳答案
Prevent Auto code change in Designer.cs for a specific line
using System;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.button1.Text = Resources.ButtonText;
}
}
}
关于c# - 如何在 *.Designer.cs C# 中替换标签文本的硬编码字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064737/