Kann ich nach der Rückkehr von Showdialog auf das Formular zugreifen? [geschlossen]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Kann ich nach der Rückkehr von Showdialog auf das Formular zugreifen? [geschlossen]

Post by Anonymous »

Ich verwende einen Werks-Methoden-Ansatz in einer Form wie folgt: < /p>

Code: Select all

// 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 == ...) { }
}
}
Ich frage mich, ob es sich um einen guten und gültigen Ansatz handelt, um auf die Formulare zuzugreifen. MyForm -Form, also würde ich darauf zugreifen, dass im Ui-Thread nach Showdialog zurückgegeben wird. Ist das problematisch?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post