Unk*_*ser 5 .net c# visual-studio c#-4.0
当我点击一个按钮时,我会尝试将窗体中的值传递给新窗体.使用:
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)
运行它,它显示正确的东西,但不传递值到第二个窗体.

我有办法将值传递给另一种形式吗?
添加一个属性
Edit item = new Edit();
item.Value = 5;
item.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
您必须定义此属性才能使用它.Edit像这样扩展你的课程:
class Edit {
...
public int Value { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2150 次 |
| 最近记录: |