且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何遍历特定表单的所有打开实例?

更新时间:2023-12-05 21:41:28

我不确定您到底要实现什么.但是在我看来,您可以迭代打开的表单的集合:

I'm not sure what exactly do you want to implement. But it seems to me that you can just iterate through the collection of opened forms:

var formsList  = Application.OpenForms.OfType<Form2>();
listBox.Items.AddRange(formsList.Select(f=>f.Text).ToArray());

此行将为您提供应用程序中所有打开的Form2实例的IEnumerable.您可能要使用自己的字符串表示形式(而不是上面代码段中使用的格式标题)

This line will give you the IEnumerable of all open Form2 instances in your application. You might want to use your own string representation (not the form caption used in the snippet above)