C#.net中的应用程序设置 [英] Application Settings in C#.net

查看:80
本文介绍了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


这篇关于C#.net中的应用程序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆