'Declaramos nuestro
metodo que hara la limpieza de los textbox
Private Sub LimpiarTextBox(ByVal ofrm As Form)
'hace un chequeo por todos los textbox
del formulario
For Each oControl As Control In ofrm.Controls
If TypeOf oCobtrol Is TextBox Then
oControl.Text = ""
End If
Next
End Sub
Private Sub
BtnPruebaLimpiarTextBox_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BtnPruebaLimpiarTextBox.Click
Call LimpiarTextBox(Me)
End Sub
Public
Class Form2
Private Sub Button1_Click(ByVal
sender As System.Object,
ByVal e As
System.EventArgs) Handles
Button1.Click
LimpiarCajas(GroupBox1)
End Sub
Sub
LimpiarCajas(ByVal Grupo As Windows.Forms.GroupBox)
Dim
caja As TextBox
For Each ctrl As Control In
Grupo.Controls
caja = TryCast(ctrl,
TextBox)
If Not (caja Is Nothing) Then
caja.Clear()
End
If
Next
ctrl
End Sub
End Class
Y para C#
// Declaramos nuestro metodo que hara la limpieza de los textbox
private void LimpiarTextBox(Form ofrm)
{
// hace un chequeo por todos los textbox del formulario
foreach (Control oControls in ofrm.Controls)
{
if (oControls is TextBox)
{
oControls.Text = ""; // eliminar el texto
}
}
}
private void BtnPruebaLimpiarTextBox_Click(System.Object sender, System.EventArgs e)
{
// pasar el formulario
LimpiarTextBox(this);
}
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 Form2 : Form
{
public
Form2()
{
InitializeComponent();
}
private
void button1_Click(object
sender, EventArgs e)
{
LimpiarCajas(groupBox1);
}
void
LimpiarCajas(System.Windows.Forms.GroupBox
Grupo)
{
TextBox
caja = default(TextBox);
foreach
(Control ctrl in
Grupo.Controls)
{
caja = ctrl as TextBox;
if
((caja != null))
{
caja.Clear();
}
}
}
}
}