【问题标题】:Best way to bind Windows Forms properties to ApplicationSettings in C#?在 C# 中将 Windows 窗体属性绑定到 ApplicationSettings 的最佳方法?
【发布时间】:2010-09-06 07:32:35
【问题描述】:

在需要认真重构的桌面应用程序中,我有几块如下所示的代码:

private void LoadSettings()
{
    WindowState = Properties.Settings.Default.WindowState;
    Location = Properties.Settings.Default.WindowLocation;
    ...
}

private void SaveSettings()
{
    Properties.Settings.Default.WindowState = WindowState;
    Properties.Settings.Default.WindowLocation = Location;
    ...
}

替换它的最佳方法是什么?项目施加的限制:

  • Visual Studio 2005
  • C#/.NET 2.0
  • Windows 窗体

更新

对于后人,我还发现了两个有用的教程:"Windows Forms User Settings in C#""Exploring Secrets of Persistent Application Settings"

我问了一个关于使用这种技术绑定表单大小here 的后续问题。我将它们分开来帮助搜索类似问题的人。

【问题讨论】:

    标签: c# .net


    【解决方案1】:

    如果您在设计器中打开 Windows 窗体,请查看属性框。第一项应该是“(ApplicationSetting)”。在那之下是“(PropertyBinding)”。在那里,您可以找到完全按照您的意愿行事的选项。

    【讨论】:

    • 您能否提供更多相关信息?
    猜你喜欢
    • 2010-09-14
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 2017-05-10
    • 1970-01-01
    • 2013-01-23
    • 1970-01-01
    相关资源
    最近更新 更多