Autor Beitrag
vit30
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 17.02.10 12:04 
Hallo!
Wie kann ich ein ausgewertete Button weiter verwenden?
Hier ist Code - Beispiel für ein Button:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
    private void button40_Click(object sender, EventArgs e)
        {
            if (sender is Button)
            {
                int i = int.Parse((sender as Button).Text);
                
            }
        }


Ich muss diese "i" weiter verwenden- mit Ergebniss von andere Auswertung multiplizieren und im Textfeld anzeigen.
Die methode hat aber Rückgabetyp void... Deswegen ist "i" "nicht sichtbar" ausserhalb der Methode.

Was kann ich machen?
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Mi 17.02.10 12:13 
Hallo,

dann musst du diese eben sichtbar machen :) Dabei wirst du wohl nicht über Member hinweg kommen. Entweder speicherst du das Ergebnis der anderen Auswertung global oder ebene diesen Wert.. je nachdem wann du dann rechnen willst:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
private void button40_Click(object sender, EventArgs e)
{
     Button b = (Button) sender;

     Multipliziere(int.Parse(b.Text), vorherigesErgebins)
}


So .. oder so ähnlich ;)

Besser wäre natürlich ein eigener ButtonTyp (mit Textfeld = int), eindeutiger Name für Button, TryParse und ein eignes EventArg.

Gruß Daniel
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 17.02.10 12:35 
Danke!
Versuche mit "Textfeld=int"
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: Mi 17.02.10 15:14 
Du kannst aber auch für jedes Control die Tag-Eigenschaft auswerten und musst lediglich beachten: nur du weißt, dass es sich um einen int handelt:
ausblenden C#-Quelltext
1:
myClassVariable = (int)(sender as Button).Tag;					

Gruß Jürgen