-1

在 Visual Studio 设计器(我使用 2012)中,无法将 ApplicationSettings 机制链接到 SelectedIndex 属性(仅限文本)。

可以改用什么解决方法?


抱歉,如果我的问题违反了 StackOverflow 规则。我搜索了我的问题,但没有找到确切的答案。

我不只知道如何自定义代码 ApplicationSettings。我总是在设计模式下使用此功能 - 我的文本框的链接文本属性,然后使用 Properties.Settings.Default.Save() 保存它,在 Form_Load 上我使用 Properties.Settings.Default.SomeName 加载保存的值。除此之外的一切都是由 VisualStudio 完成的,我不知道究竟要根据我的需要改变它的行为。

我确信这个问题对初学者很有用

4

1 回答 1

2

写一些代码,就像使用设计器一样简单,而且设计器生成的代码太多你看不懂。

在此处输入图像描述

在 Visual Studio 中编辑 Settings,添加一个名为“SelectedIndex”的属性,将其 Type 设置为 int,并将 Scope 设置为User,Value 为 0(表示选择了第一项)。您可以在代码中访问此属性:

public Form1()
{
    InitializeComponent();
    comboxBox1.SelectedIndex = Properties.Settings.Default.SelectedIndex;
    this.Closing += Form1_Closing;
}

void Form1_Closing(object sender, CancelEventArgs e)
{
    Properties.Settings.Default.SelectedIndex = comboxBox1.SelectedIndex;
    Properties.Settings.Default.Save();
}
于 2014-12-13T11:40:45.970 回答