Asgorath Posted January 24, 2006 at 10:23 AM Report #12363 Posted January 24, 2006 at 10:23 AM Option Explicit On Option Strict On Imports System.Reflection Class ClassLimpaTexto '' Versão 1 - dia 20-04-2004 '' Classe para percorrer todos os controlos/componentes de um form e que limpa as respectivas caixas de texto ou comboboxes. #Region "Revisões" '' Revisão 1 - dia 17-08-2004 '' Novo procedure LimpaCheckBoxes #End Region Public Sub LimpaTextBoxes(ByVal f As Form) '' limpa os textboxes Dim meuForm As Type = f.GetType() Dim campos As FieldInfo() = meuForm.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic) For Each campo As FieldInfo In campos If campo.FieldType.Name.ToLower = "textbox" Then Dim t As TextBox = DirectCast(campo.GetValue(f), TextBox) t.Text = String.Empty End If Next End Sub Public Sub LimpaComboBoxes(ByVal f As Form) '' limpa os comboboxes Dim meuForm As Type = f.GetType() Dim campos As FieldInfo() = meuForm.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic) For Each campo As FieldInfo In campos If campo.FieldType.Name.ToLower = "combobox" Then Dim c As ComboBox = DirectCast(campo.GetValue(f), ComboBox) c.Text = String.Empty End If Next End Sub Public Sub LimpaCheckBoxes(ByVal f As Form) '' desactiva os checkboxes Dim meuForm As Type = f.GetType() Dim campos As FieldInfo() = meuForm.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic) For Each campo As FieldInfo In campos If campo.FieldType.Name.ToLower = "checkbox" Then Dim c As CheckBox = DirectCast(campo.GetValue(f), CheckBox) c.Checked = False End If Next End Sub Public Sub LimpaRadioButton(ByVal f As Form) '' desactiva os radiobuttons Dim meuForm As Type = f.GetType() Dim campos As FieldInfo() = meuForm.GetFields(BindingFlags.Instance Or BindingFlags.NonPublic) For Each campo As FieldInfo In campos If campo.FieldType.Name.ToLower = "radiobutton" Then Dim c As RadioButton = DirectCast(campo.GetValue(f), RadioButton) c.Checked = False End If Next End Sub End Class Como usar : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim limpa As New ClassLimpaTexto limpa.LimpaTextBoxes(Me) End Sub Atentamente Jorge "The Dark Side Clouds Everthing. Impossible To See The Future Is."My rig: Intel Core 2 Quad Q9450 | abit IP35P | 4G Kingston 800 Mhz | XFX GeForce 9800 GX2 1G ddr3 | 2X WD5000AAJS 500Gb Sata 2 | PSU 600W || Caixa El-Diablo | Creative XMod
deathseeker25 Posted January 24, 2006 at 03:02 PM Report #12391 Posted January 24, 2006 at 03:02 PM Um bom tutorial Asgorath. Sou um newb em VB.NET, mas fico contente ao saber que existe gente a querer dar este tipo de contributo ao forum. Cumps
Dabubble Posted January 24, 2006 at 07:05 PM Report #12417 Posted January 24, 2006 at 07:05 PM Muito a frente!! Ja tinha utilizado reflection em Java e da mesmo muito jeito (principalmente em middleware). Ja agora sabes se esses componentes podem ser componenentes web?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now