[英]Can you change the name of a C# Winforms button via the App.config file?
我有一个带有按钮的Winforms应用程序,当单击该按钮时,它会转到各个内部和外部位置(网络位置/ Web路径),我被问到最终用户是否可以使用自己的按钮名称,而不是我所谓的按钮名称。
我创建了一个App.config文件,因此,如果链接更改,它们至少可以编辑该文件以反映路径/ URL等的更改
按钮属性文本字段似乎不允许后面有代码。
private void GoogleS_Click(object sender, EventArgs e)
{
try
{
string GoogleS = ConfigurationManager.AppSettings["Google"];
Process.Start(GoogleS);
}
catch (Exception GoogleErr)
{
MessageBox.Show(GoogleErr.Message);
}
}
以及App.config文件中的键
<add key="Google" value="http://www.google.com/" />
和修复
App.config
<add key="GoogleButton" value="Google Search"/>
<add key="GoogleLink" value="http://www.google.com"/>
//Code for the Button names which are loaded on Form Loading from the App.config file
private void CSS_Load(object sender, EventArgs e)
{
btnGoogleS.Text = ConfigurationManager.AppSettings["GoogleButton"];
}
private void btnGoogleS_Click(object sender, EventArgs e)
{
try
{
string GoogleS = ConfigurationManager.AppSettings["GoogleLink"];
Process.Start(GoogleS);
}
catch (Exception GoogleErr)
{
MessageBox.Show(GoogleErr.Message);
}
}
private void btnGoogleS_MouseHover(object sender, EventArgs e)
{
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.btnGoogleS, (ConfigurationManager.AppSettings["GoogleLink"]));
}
您可以手动设置按钮标题:
btnGoogle.Text = ConfigurationManager.AppSettings["GoogleCaption"];
可能您将在Form Load处理程序中执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.