Hi Palladin,
ich habe 4 Textboxen, Buttons und 4 Felder dieser Art. Bisher hatte ich dafür 4 Button-Click-Event-Methoden, die praktisch alle das gleiche machen, nur das halt verschiedene Controls usw verwendet werden. Also dacht ich mir, das kann man optimieren und das in einer Methode zusammenfassen.
Soweit war ich bis jetzt:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
| private void buttonSearchSaveFolder_Click(object sender,EventArgs e) { if (sender != null) { Button button = sender as Button; TextBox txtBox = null; ref string path;
if (button.Name == "buttonSearchSaveFolder") { txtBox = this.textBoxSaveFolderPath; path = this.DefaultFolderPath; } else if (button.Name == "buttonClaimSearchSaveFolder") { txtBox = this.textBoxClaimPath; path = this.ClaimFolderPath; } else if (button.Name == "buttonMasterSearchSaveFolder") { txtBox = this.textBoxMasterPath; path = this.MasterFolderPath; } else if (button.Name == "buttonSchittAGSearchSaveFolder") { txtBox = this.textBoxSchnittAGPath; path = this.SchnittAGPath; } else { txtBox = new TextBox(); path = null; }
this.folderBrowserDialog1.SelectedPath = txtBox.Text; if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) { txtBox.Text = this.folderBrowserDialog1.SelectedPath; if (path != null) path = this.folderBrowserDialog1.SelectedPath; } } } |
Also ich wollt mir einfach durch das Referenzieren von
path eine 2. If-Abfrage sparen, um dann über den Button das richtige Feld herauszufinden.
Gibt es da keine Möglichkeit, wie das ungefähr funktionieren könnte?