当我点击一个按钮时,我会尝试将窗体中的值传递给新窗体.使用:
private void Edit_button_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
Edit item = new Edit(int.Parse(listBox1.SelectedIndex.ToString()));
item.ShowDialog();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,它没有显示我设计的表单,而是显示了这个

但是当我将代码更改为:
Edit item = new Edit();
item.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
运行它,它显示正确的东西,但不传递值到第二个窗体.

我有办法将值传递给另一种形式吗?
我试图将一个字符串从一个文本文件拆分成一个数组,以便我可以将它们存储在一个类中但它不工作; 它没有拆分它,它在textfile.txt中返回相同的格式
using (StreamReader reader = new StreamReader("textfile.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
char[] delimiters = new char[] { '\t' };
string[] parts = line.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parts.Length; i++)
{
MessageBox.Show(parts[i]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
文本文件包含:
George\t15\tStudent\tAddress\tB:\temp\profilepic.png
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样(分裂后):
George
15
Student
Address
profilepic.png
Run Code Online (Sandbox Code Playgroud)
任何想法或帮助表示赞赏.