Sharpdevelop Access resource file settings

大城市里の小女人 提交于 2019-12-11 16:25:32

问题


I'm trying to access settings from a settings file(MySettings) that I have created through the SharpDevelop Template:

Setting:

[global::System.Configuration.UserScopedSettingAttribute()]
        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [global::System.Configuration.DefaultSettingValueAttribute("")]
        public string s_Username {
            get {
                return ((string)(this["s_Username"]));
            }
            set {
                this["s_Username"] = value;
            }
        }
    }

Code:

void MainFormLoad(object sender, EventArgs e)
    {

        MessageBox.Show(AdhesionCharting.Properties.MySettings.s_Username);

    }

Error:

'AdhesionCharting.Properties.MySettings' is a 'type', which is not valid in the given context


回答1:


If you look at your MySettings.cs file you will see that the class is not static. There is a Default property which is static that can be used. So your code should be changed to be:

void MainFormLoad(object sender, EventArgs e)
{
    MessageBox.Show(AdhesionCharting.Properties.MySettings.Default.s_Username);
}


来源:https://stackoverflow.com/questions/38934422/sharpdevelop-access-resource-file-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!