Код: Выделить всё
// MyForm.cs
private MyForm() { }
private string Foo()
{
// this would be called after ShowDialog returned
string s = "";
foreach (Label l in MyLabels)
s += l.Text;
}
// this would be called after ShowDialog returned
private int Bar => label1.Text.Length;
public static bool ShowMyForm(out string s, out int i)
{
using (MyForm f = new MyForm())
{
bool ok = f.ShowDialog() == DialogResult.OK;
// accessing Controls of f after ShowDialog returned
s = f.Foo();
i = f.Bar;
return ok; // User clicked OK or Cancel
}
}
// Other Form
void CallForm()
{
if (MyForm.ShowMyForm(out string s, out int i)
{
if (s == ...) { }
if (i == ...) { }
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... g-returned