如何从用户控件访问默认设置
本文关键字:访问 默认 设置 控件 用户 | 更新日期: 2023-09-27 18:14:45
如何从用户控件访问默认设置?
当我使用这个代码
时namespace SearchControl{
public partial class SearchControl : UserControl
{
string ConncStr = Properties.Settings["myConnectionString"].toString();
}}
not working
Properties.Settings["myConnectionString"].toString()
我想访问属性。设置("myConnectionString")
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var secGroup = config.SectionGroups["userSettings"]; // or applicationSettings
if (secGroup != null)
{
var clientSettings = (ClientSettingsSection)secGroup.Sections[0];
var settingElementCollection = clientSettings.Settings;
var setting = settingElementCollection.Get(Name);
var value = setting.Value.ValueXml.InnerText;
}
string conStr = Properties.Settings.Default.myConnectionString;
大多数语句以;
而不是}
结尾
namespace SearchControl;
public partial class SearchControl : UserControl
{
string ConncStr = Properties.Settings.Default.myConnectionString;
}
见https://msdn.microsoft.com/en-us/library/bb397759 (v = vs.110) . aspx