C# 保存单个用户的Windows窗体应用程序组合框和文本框选择,并使用按钮加载它们
我有一个用c#编写的windows窗体应用程序。它有一个文本框、一个组合框和一个按钮。该按钮是一个保存按钮,用于保存用户在文本框中输入的值,并在单击时将combobox设置为,并且应该能够保存多个不同的选择,例如一个用户向文本框添加“test1”并选择combobox的0索引选项,然后单击保存按钮保存这些选项,然后,另一个用户可以将“test2”添加到文本框中,并选择组合框的2索引选项,然后单击save按钮保存这些选项,从而生成两个单独保存的选项,这些选项可以加载回应用程序,从而使表单选择保存文件数据 问题是我不知道如何实现这样的功能,也不知道从哪里开始。我已经研究过将用户的选项保存为xml文件,但显然这不能用组合框数据来完成 这是一张我想做的事情的图表C# 保存单个用户的Windows窗体应用程序组合框和文本框选择,并使用按钮加载它们,c#,visual-studio,C#,Visual Studio,我有一个用c#编写的windows窗体应用程序。它有一个文本框、一个组合框和一个按钮。该按钮是一个保存按钮,用于保存用户在文本框中输入的值,并在单击时将combobox设置为,并且应该能够保存多个不同的选择,例如一个用户向文本框添加“test1”并选择combobox的0索引选项,然后单击保存按钮保存这些选项,然后,另一个用户可以将“test2”添加到文本框中,并选择组合框的2索引选项,然后单击save按钮保存这些选项,从而生成两个单独保存的选项,这些选项可以加载回应用程序,从而使表单选择保存文
关于如何在c#中的Visual Studio Windows窗体应用程序中实现此功能,或者从何处开始,您有什么建议吗?可以使用txt文件实现此功能。我使用它们是因为它们相当简单 要保存:
private void SaveButton_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Text files (*.txt)|*.txt";
sfd.ShowDialog();
string name = sfd.Title;
string filePath = sfd.FileName;
StreamWriter sw = new StreamWriter(filePath);
// Write the text you want to the file.
sw.WriteLine(MyTextBox.Text);
sw.WriteLine(MyComboBox.SelectedIndex);
// You could do MyComboBox.SelectedItem if you evaluate what index the item
// belongs at when reading back the file for the load function.
sw.Close();
}
要加载:
private void LoadButton_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text files (*.txt)|*.txt";
ofd.ShowDialog();
// If the user doesn't select a file, cancels, or exists the dialogue box
nothing is done.
if (ofd.FileName == null || ofd.FileName.Equals("")) { }
// Else if the user has selected a file, the file's text is converted when necessary, and used to change the value of the applications controls.
else
{
// Get the contense of the txt file as a string array.
string[] list = File.ReadAllLines(ofd.FileName);
// Reads the text stored in the txt file and puts it as the value for the boxes.
MyTextBox.Text = list[0];
MyComboBox.SelectedIndex = list[1];
}
}你可以从这里开始:谢谢,但我已经解决了。稍后将解释如何进行。