Settings.settings文件的用处

37 篇文章 0 订阅

1、定义

在Settings.settings文件中定义配置字段。把作用范围定义为:User则运行时可更改,Applicatiion则运行时不可更改。可以使用数据网格视图,很方便;

2、读取配置值

text1.text = Properties.Settings.Default.FieldName;
//FieldName是你定义的字段

3、修改和保存配置

Properties.Settings.Default.FieldName = "server";

Properties.Settings.Default.Save();//使用Save方法保存更改

4、也可以自己创建

创建一个配置类FtpSetting。在WinForm应用程序里,一切配置类都得继承自 ApplicationSettingsBase 类。

sealed class FtpSettings : ApplicationSettingsBase

{
[UserScopedSetting]
[DefaultSettingValue("127.0.0.1")]
public string Server
{
get { return (string)this["Server"]; }
set { this["Server"] = value; }
}
[UserScopedSetting]
[DefaultSettingValue("21")]
public int Port
{
get { return (int)this["Port"]; }
set { this["Port"] = value; }
}
}


使用上述配置类,可以用:

private void button2_Click(object sender, EventArgs e)
{
FtpSettings ftp = new FtpSettings();
string msg = ftp.Server + ":" + ftp.Port.ToString();
MessageBox.Show(msg);
}


我们在使用上述FtpSetting 配置时,当然要先进行赋值保存,然后再使用,后面再修改,再保存,再使用。
private void button2_Click(object sender, EventArgs e)
{
FtpSettings ftp = new FtpSettings();
ftp.Server = "ftp.test.com";
ftp.Port = 8021;
ftp.Save();
ftp.Reload();
string msg = ftp.Server + ":" + ftp.Port.ToString();
MessageBox.Show(msg);
}
嗯。已经Save了,你可能会在应用程序文件夹里找不到它到底保存到哪里去了。由于我们是用UserScope的,所以其实该配置信息是保存到了你的Windows的个人文件夹里去了。比如我的就是 C:\Documents and Settings\brooks\Local Settings\Application Data\TestWinForm目录了。

--------------------- 上述来自 xwygn 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/xwygn/article/details/7204405?utm_source=copy

下述为个人扩充:

[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
    internal sealed partial class PacsSetting : global::System.Configuration.ApplicationSettingsBase {
        
        private static PacsSetting defaultInstance = ((PacsSetting)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new PacsSetting())));
        
        public static PacsSetting Default {
            get {
                return defaultInstance;
            }
        }

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在IntelliJ IDEA中,Maven是一种用于构建和管理Java项目的强大工具。在Maven的配置中,"User setting file"是指用户级别的Maven配置文件,通常称为`settings.xml`。 "User setting file"的作用是定义Maven全局配置和个人设置。通过编辑这个文件,您可以配置全局的Maven设置,包括仓库地址、代理设置、构建配置等。 下面是一些常见的用途和配置示例: 1. 配置本地仓库路径:您可以在`settings.xml`文件中指定本地Maven仓库的路径。例如: ```xml <localRepository>/path/to/local/repository</localRepository> ``` 2. 配置远程仓库:您可以在`settings.xml`文件中添加或修改Maven远程仓库的配置,以便下载和上传依赖项。例如: ```xml <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> ``` 3. 配置代理:如果您需要通过代理服务器访问远程仓库,可以在`settings.xml`文件中添加代理配置。例如: ```xml <proxies> <proxy> <id>proxy</id> <active>true</active> <protocol>http</protocol> <host>proxy.example.com</host> <port>8080</port> <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts> </proxy> </proxies> ``` 除了上述示例,`settings.xml`文件还可以配置很多其他的Maven设置,如镜像仓库、构建相关的配置、用户认证等。 请注意,`settings.xml`文件通常位于Maven的安装目录的`conf`文件夹下。在IntelliJ IDEA中,"User setting file"指的是您个人用户目录下的Maven配置文件,通过该设置文件,您可以覆盖全局配置,以适应特定的项目或个人需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值