Autor Beitrag
Levsen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 17.06.08 10:15 
Hallo ich habe vor ein ein paar Tagen mit C# angefangen und nutze Visual C# Express Edition 2008 und wollte einen Taschenrechner machen.

Zahlen kann man eingeben nur kann man noch nicht rechnen ^^

Ich bräuchte einen Code für das PLUS (+) Rechnen von 2 zahlen

So sieht mein Taschenrechner aus
user defined image

Man soll eine zahl eingeben dann + drücken und dann wida eine zahl eingeben und dann auf gleich klicken und das ergebniss bekommen

Das ist mein Source Code
ausblenden volle Höhe C#-Quelltext
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:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void zahl_07_Click(object sender, EventArgs e)
        {
            TextBox.Paste("7");
        }

        private void zahl_08_Click(object sender, EventArgs e)
        {
            TextBox.Paste("8");
        }

        private void zahl_09_Click(object sender, EventArgs e)
        {
            TextBox.Paste("9");
        }

        private void zahl_04_Click(object sender, EventArgs e)
        {
            TextBox.Paste("4");
        }

        private void zahl_05_Click(object sender, EventArgs e)
        {
            TextBox.Paste("5");
        }

        private void zahl_06_Click(object sender, EventArgs e)
        {
            TextBox.Paste("6");
        }

        private void zahl_01_Click(object sender, EventArgs e)
        {
            TextBox.Paste("1");
        }

        private void zahl_02_Click(object sender, EventArgs e)
        {
            TextBox.Paste("2");
        }

        private void zahl_03_Click(object sender, EventArgs e)
        {
            TextBox.Paste("3");
        }

        private void zahl_00_Click(object sender, EventArgs e)
        {
            TextBox.Paste("0");
        }

        private void point_Click(object sender, EventArgs e)
        {
            TextBox.Paste(".");
        }

        private void plus_Click(object sender, EventArgs e)
        {

        }

        private void TextBox_TextChanged(object sender, EventArgs e)
        {

        }

    }
}


Ich wäre sehr dankbar wenn jemand mir denn Code für PLUS (+) Rechnen gibt
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 17.06.08 10:26 
Hallo!

Fertigen Code geben wir hier sehr ungerne, wir helfen lieber, dass Du den selber rausbekommst :-)

Wie sieht denn Dein Ansatz aus, um das zu realisieren und wo hakt es dann konkret?

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
neno
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Di 17.06.08 10:39 
Eine ganz andere Frage, ist dieses Vista? Design in 2008 vorhanden, oder wie läuft das?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 17.06.08 10:47 
user profile iconneno hat folgendes geschrieben:
Eine ganz andere Frage, ist dieses Vista? Design in 2008 vorhanden, oder wie läuft das?
Da das eine ganz andere Frage ist, hat die auch nix in diesem Thread zu suchen ;-) Erstelle daher bitte einen eigenen Thread. Danke! :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Levsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 17.06.08 10:56 
Das wäre eine Idee ^^
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
private void plus_Click(object sender, EventArgs e)
        {
          int erg
          if op = "+" erg = zahl1 + zahl2
        }


Ich habe Vista Ultimate und Visual C# Express Edition 2008
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4798
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 17.06.08 11:07 
Schon ganz gut, aber du solltest 'erg' zu einer Klassenvariablen machen, damit das Ergebnis dauerhaft gespeichert wird und du es beim nächsten Klick weiterverwenden kannst.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 17.06.08 11:14 
Ein paar Fehler in der Syntax sind auch noch drin: Prüfen auf Gleichheit geht mit "==" und die Bedingung in einer if-Anweisung muss in Klammern gesetzt werden.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Levsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 17.06.08 11:16 
Wie muss ich "erg" dann ändern

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
private void plus_Click(object sender, EventArgs e)
        {
          int erg
          if op = "+" erg = (zahl1 + zahl2)
        }


Ist das schon besser ^^
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 17.06.08 11:34 
Nein, eigentlich nicht. Schau Dir mal im Suche bei Google "OPENBOOK VISUAL C#" an, wie eine if-Anweisung aussehen muss. Insbesondere, was davon die Bedingung ist, um welche die Klammern drum müssen ;)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Levsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 17.06.08 11:54 
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
private void plus_Click(object sender, EventArgs e)
        {
          int erg
          if (op = "+" erg) == zahl1 + zahl2
        }


:D ich teste einfach mal rum aber vom anstaz ist das richtig ?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Di 17.06.08 11:56 
user profile iconLevsen hat folgendes geschrieben:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
private void plus_Click(object sender, EventArgs e)
        {
          int erg
          if (op = "+" erg) == zahl1 + zahl2
        }


:D ich teste einfach mal

Was soll das? Ich hab keine Lust, dass Du das Forum mit sinnlosen Versuchen vollklatschst, obwohl es mit einmal nachlesen getan wäre. Lesen ist keine Schande, also guck Dir bitte das Buch an, welches ich genannt habe.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".