C#.net中的应用程序设置
大家好,
我在我的项目中使用应用程序设置.需要您的帮助.如何在C#.net中为动态属性创建应用程序设置.我的测试项目中有4个文本框和3个按钮.
Button1-用于创建动态文本框
Button2-将动态文本框值保存到应用程序设置中
Button3-将值从应用程序设置检索到动态文本框
谢谢
问候,
Lakshmi Narayanan.S
Hi All,
I am using Application settings in My Project.I need your help.How to create a Application settings for Dynamic Property in C#.net.I have 4 Textbox and 3 Buttons in my Testing Project.
Button1 -- For Creating a Dynamic Textbox
Button2 -- To save Dynamic textbox value into Application Setting
Button3 -- To retrieve value from Application settings to Dynamic textbox
Thanks
Regards,
Lakshmi Narayanan.S
希望 ^ ]可能会为您提供帮助.
基于此开发您的应用程序设置.
Hope this[^] might help you.
Based on this develop your application setting.
要动态写入app.config,请查看 ^ ]
干杯,
Balaji
To dynamically write to app.config, pls look into Read/Write App.Config File with .NET 2.0[^]
Cheers,
Balaji
我假设这是Windows应用程序.要在这种类型的应用程序中获取和设置应用程序设置",请使用
I am assuming this is a Windows Application. To get and set Application Settings in this type of application you use
Properties.Settings.Default.yourSettingName
.因此,对于您的示例,您需要执行以下操作:
. Thus for your example you would need to do something like this:
private void btnAddTextBox_Click(object sender, EventArgs e)
{
//add dynamic textbox
TextBox tb = new TextBox();
tb.Top = btnAddTextBox.Top;
tb.Left = btnAddTextBox.Left + btnAddTextBox.Width + 5;
tb.Visible = true;
tb.Name = "dynamicText";
this.Controls.Add(tb);
}
private void btnSaveToSettings_Click(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl is TextBox)
{
if (ctrl.Name == "dynamicText")
{
//save to settings
Properties.Settings.Default.dynamicText = ctrl.Text;
}
}
}
}
private void btnRetrieveFromSettings_Click(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl is TextBox)
{
if (ctrl.Name == "dynamicText")
{
//set text to setting
ctrl.Text = Properties.Settings.Default.dynamicText;
}
}
}
}
假设您在app.config文件中有一个名为dynamicText
的设置
希望对您有帮助
This assumes you have a setting in your app.config file called dynamicText
Hope this helps