-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC#.NET_Forms.cs
334 lines (294 loc) · 7.89 KB
/
C#.NET_Forms.cs
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace [Proyecto]
{
// Comentarios multi-linea
/*
*/
public partial class [Form] : Form
{
// Procedimiento
void [Procedimiento](){
}
// Obtener información de ensamblado de aplicación/Proyecto
void AppInfo()
{
string AppTit = Application.ProductName;
string AppDev = Application.CompanyName;
string AppVer = Application.ProductVersion;
}
// MessageBox.Show
void MessageBoxShow()
{
MessageBox.Show("");
// MessageBox multilinea
MessageBox.Show([Linea 1] + Environment.NewLine + [Linea 2] + Environment.NewLine + [Linea N]);
// If MessageBox.Show
if (MessageBox.Show("", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
}
else
{
}
}
// Instrucción Try Catch
void TryCatch()
{
try
{
}
catch (Exception ex)
{
// Cuadro de mensaje (WinForms)
MessageBox.Show(ex.Message);
// Alamcenar en variable para uso posterior
string [Variable] = ex.Message;
}
}
/*
Instrucción If Else
&& = AND
|| = OR
== es = (Igual a...)
!= es <> (Diferente de...)
*/
void IfElse()
{
// Forma 1
if ([Operacion logica])
{
}
else
{
}
// Forma 2
if ([Operacion logica])
{
}
else if ([Operacion logica])
{
}
}
// Instrucción Switch (Select Case)
void SelCase()
{
switch ([Variable])
{
case [Value1]:
[Instrucción1]
break;
case [Value2]:
[Instrucción2]
break;
case [ValueN]:
[Instrucción3]
break;
default:
[Instrucción]
break;
}
}
// Formatos
void TxtFormt()
{
// MaxLength
[TextBox].MaxLength = [Longitud];
// TextBox PasswordChar
[TextBox].UseSystemPasswordChar = [true/false];
// TextAlign
[TextBox].TextAlign = HorizontalAlignment.[Center/Right/Left] ;
// CharacterCasing
}
// Llamar clases
void CallClass()
{
[Clase] [Variable] = new [Clase]();
/*
.Net 5.0 en adelante
[Clase] [Variable] = new();
*/
}
// Instrucción Show para mostrar Forms, similar al llamdo de clase
void ShowForms()
{
[Form] [Variable] = new [Form]();
[Variable].Show();
// Mostrar Form unida con instrucción frm_closing
[Variable].FormClosing += Frm_Closing;
}
// Cerrar/Ocultar Forms
void EndProj()
{
// Equivalente End
Environment.Exit(0);
// Equivalente Me.Close()
this.Close();
// Ocultar
this.Hide();
}
// Mostrar Form al cerrar otro Form sin necesidad de un evento FormClosed
private void Frm_Closing(object sender, FormClosingEventArgs e)
{
this.Show();
}
// Crear variable String multi-linea
void StringML()
{
StringBuilder [Variable] = new StringBuilder();
// StringBuilder [Variable] = new();
// Linea 1
[Variable].AppendLine("");
// Linea 2
[Variable].AppendLine("");
// Linea N
[Variable].AppendLine("");
}
// Unir cadenas string &
void UnirCadenas()
{
[String] = String.Concat([String 1] , [String 2]),... [String N];
}
// Solo recibir numeros en un TextBox (int 0), mediante evento KeyPress
public void OnlyNumbers(KeyPressEventArgs e)
{
e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
}
// Solo recibir numeros en un TextBox y una coma (decimal 0,0), mediante evento KeyPress
public void NumDecim(object sender, KeyPressEventArgs e)
{
}
// Realizar cálculos básicos con TextBox/Variable
void Calcular()
{
string Operacion;
int/decimal [Variable 1], [Variable 2], [Variable 3];
/*
Int32 = Números enteros de -2.147.483.648 a 2.147.483.647 (9 cifras 000.000.000)
Int64 = Números enteros de -9.223.372.036.854.775.808 a 9.223.372.036.854.775.807 (18 cifras 000.000.000.000.000.000)
*/
[Variable 1] = Convert.ToInt64/ToDecimal([TextBox1]);
[Variable 2] = Convert.ToInt64/ToDecimal([TextBox2]);
// Suma
[Variable 3] = [Variable 1] + [Variable 2];
// Resta
[Variable 3] = [Variable 1] - [Variable 2];
// Multiplicación
[Variable 3] = [Variable 1] * [Variable 2];
// División
[Variable 3] = [Variable 1] / [Variable 2];
// Mostrar resultado
[TextBox3] = [Variable 3].ToString();
}
// Capturar datos de un DataGridView
void CellE()
{
try
{
// Mostrar datos texto en un Label/TextBox/Variable
[Label/TextBox] = [DataGridView].CurrentRow.Cells[Columna].Value.ToString();
// Mostrar datos bit/boolean en un CheckBox
object [Variable] = [DataGridView].CurrentRow.Cells[Columna].Value;
[CheckBox].Checked = Convert.ToBoolean([Variable]);
// Mostrar datos blob/longblob/varbinary en un PictureBox
var [Variable 1] = (Byte[])[DataGridView].CurrentRow.Cells[Columna].Value;
var [Variable 2] = new MemoryStream([Variable 1);
[PictureBox].Image = Image.FromStream([Variable 2]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// Cambiar el ancho/nombre de las columnas de un DataGridView
void CellZ()
{
try
{
// Ancho de columna
[DataGridView].Columns[Columna].Width = [Value];
// Texto/cabecera de columna
[DataGridView].Columns[Columna].HeaderText = [Text];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// Cambiar los colores de las filas de un DataGridView
void ColorsDGV()
{
[DataGridView].RowsDefaultCellStyle.BackColor = Color.[Color];
[DataGridView].AlternatingRowsDefaultCellStyle.BackColor = Color.[Color];
}
void ClearDGV()
{
[DataGridView].Columns.Clear();
}
// No permitir modificación de datos en un ComboBox
void PropCBx()
{
[ComboBox].DropDownStyle = ComboBoxStyle.DropDownList;
[ComboBox].FlatStyle = FlatStyle.Popup;
}
// Borrar los items de un ComboBox cuando no están rellenados por medio de un DataSet
void ClearCBx()
{
[ComboBox].Items.Clear();
[ComboBox].ResetText();
}
// Maximizar ventana con FormBorderStyle: None sin cubrir toda la pantalla
void MaxRestForm()
{
}
// Captar valores de fecha (yyyy/mm/dd) y hora (hh:mm:ss) de un DateTimePicker
string Fecha, Hora;
void MyDateTime()
{
Fecha = ;
Hora = ;
}
// Configurar un OpenFileDialog en un para cargar una imagen en un PictureBox
void OFile()
{
OpenFileDialog [Variable] = new OpenFileDialog
{
Filter = "Imagenes JPG|*.jpg|Imagenes JPEG|*.jpeg|Imagenes PNG|*.png",
Title = "Seleccionar imagen",
FilterIndex = 1,
RestoreDirectory = true
};
if ([Variable].ShowDialog() == DialogResult.OK)
{
[PictureBox].Image = Image.FromFile([Variable].FileName);
}
}
// Abrir formularios para una unica pantalla
private void AbrirForm(object FormA)
{
// Vaciar panel en caso de tener otro form abierto
if ([Panel].Controls.Count > 0)
{
[Panel].Controls.RemoveAt(0);
}
Form [Variable] = FormA as Form;
[Variable].TopLevel = false;
[Variable].Dock = DockStyle.Fill;
[Variable].BackColor = BackColor;
[Panel].Controls.Add([Variable]);
[Panel].Tag = [Variable];
[Variable].Show();
}
// Mostrar respectivo Form llamando 'AbrirForm'
void Abrir()
{
AbrirForm(new [Form]());
}
}
}