Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

...FormsApplication2\WindowsFormsApplication2\Form1.

cs 1
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10
11 namespace WindowsFormsApplication2
12 {
13 public partial class Form1 : Form
14 {
15 public Form1()
16 {
17 InitializeComponent();
18 }
19
20 private void btnsuma_Click(object sender, EventArgs e)
21 {
22 if (validarFormulario())
23 {
24 int x = Convert.ToInt32(txt1.Text);
25 int y = Convert.ToInt32(txt2.Text);
26 realizarSuma(x, ref y);
27 }
28 }
29
30 private bool validarFormulario()
31 {
32 if (txt1.Text.Trim() == "")
33 {
34 txt1.Focus();
35 MessageBox.Show("Error Numero 1 no válido");
36 return false;
37 }
38 if (txt2.Text.Trim() == "")
39 {
40 txt2.Focus();
41 MessageBox.Show("Error Numero 2 no válido");
42 return false;
43 }
44
45 return true;
46
47
48 }
49
50 private void realizarSuma(int x,ref int y)
51 {
52 // y = y + 10;
53 MessageBox.Show("La suma es : " + (x+y).ToString());
...FormsApplication2\WindowsFormsApplication2\Form1.cs 2
54 }
55
56 private void btnresta_Click(object sender, EventArgs e)
57 {
58 int x = Convert.ToInt32(txt1.Text);
59 int y = Convert.ToInt32(txt2.Text);
60 realizarResta(x,y);
61 }
62
63 private void realizarResta(int x, int y)
64 {
65
66 MessageBox.Show("La resta es : " + (x - y).ToString());
67
68 }
69
70 private void btnmultiplicacion_Click(object sender, EventArgs
e)
71 {
72 int x = Convert.ToInt32(txt1.Text);
73 int y = Convert.ToInt32(txt2.Text);
74 realizarMultiplicacion(x,y);
75 }
76
77 private void realizarMultiplicacion(int x, int y)
78 {
79
80 MessageBox.Show("La Multiplicación es : " + (x *
y).ToString());
81
82 }
83
84 private void btndivision_Click(object sender, EventArgs e)
85 {
86 int x = Convert.ToInt32(txt1.Text);
87 int y = Convert.ToInt32(txt2.Text);
88
89 realizarDivision(x,y);
90 }
91
92 private void realizarDivision(int x, int y)
93 {
94
95 MessageBox.Show("La División es : " + (x / y).ToString());
96
97 }
98
99 private void txt1_KeyPress(object sender, KeyPressEventArgs e)
100 {
101 int tecla = Convert.ToInt32(e.KeyChar);
102 if ((tecla >= 48 && tecla <= 57)|| tecla==8 || tecla==13)
103 {
104 e.Handled = false;
...FormsApplication2\WindowsFormsApplication2\Form1.cs 3
105 if (tecla==13)
106 {
107 txt2.Focus();
108 }
109
110 }
111 else
112 {
113 e.Handled = true;
114 MessageBox.Show(tecla.ToString());
115 }
116
117 }
118
119 private void txt2_KeyPress(object sender, KeyPressEventArgs e)
120 {
121 int tecla = Convert.ToInt32(e.KeyChar);
122 if ((tecla >= 48 && tecla <= 57) || tecla == 8 || tecla ==
13)
123 {
124 e.Handled = false;
125 if (tecla == 13)
126 {
127 btnsuma.Focus();
128 }
129
130 }
131 else
132 {
133 e.Handled = true;
134 MessageBox.Show(tecla.ToString());
135 }
136
137 }
138 }
139 }
140

You might also like