LIMPAR FORM

CAPITAO.GARCIA 02/02/2011 14:15:22
#364131
Boa tarde pessoal...

Sou iniciante em C#, e to com um probleminha pra limpar o form
meu código tá assim:

          private void Limpa(Form f)
{
foreach (Control ctl in f.Controls)
{
if ((typeof(ctl) is TextBox) || (typeof(ctl) is MaskedTextBox))
{
ctl.Text = [Ô][Ô];
}
}

}


Tentei puxar a lógica de como eu fazia no VB6, mas dá o seguinte erro ao compilar:

Citação:

The type or namespace name [ô]ctl[ô] could not be found (are you missing a using directive or an assembly reference?) D:\Projetos\Contas\CAP\CAP\frmCAP.cs



Alguém sabe o que pode ser?

Grato desde já!
RODRIGOFERRO 02/02/2011 14:24:00
#364132
Resposta escolhida
Rotina recursiva que limpa os controles especificados abaixo, até os que estao em panels e groupboxes... o controle que quizer acrescentar e tirar, é so modificar abaixo !

        public static void ClearForm(System.Windows.Forms.Control parent)
{
foreach (System.Windows.Forms.Control ctrControl in parent.Controls)
{
//Loop through all controls
if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.TextBox)))
{
//Check to see if it[ô]s a textbox
((System.Windows.Forms.TextBox)ctrControl).Text = string.Empty;
//If it is then set the text to String.Empty (empty textbox)
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RichTextBox)))
{
//If its a RichTextBox clear the text
((System.Windows.Forms.RichTextBox)ctrControl).Text = string.Empty;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.ComboBox)))
{
//Next check if it[ô]s a dropdown list
((System.Windows.Forms.ComboBox)ctrControl).SelectedIndex = -1;
//If it is then set its SelectedIndex to 0
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.CheckBox)))
{
//Next uncheck all checkboxes
((System.Windows.Forms.CheckBox)ctrControl).Checked = false;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RadioButton)))
{
//Unselect all RadioButtons
((System.Windows.Forms.RadioButton)ctrControl).Checked = false;
}
if (ctrControl.Controls.Count > 0)
{
//Call itself to get all other controls in other containers
ClearForm(ctrControl);
}
}
}


//Example call
ClearForm(this);


Abraços
CAPITAO.GARCIA 02/02/2011 15:14:27
#364135
Obrigado ZEROCAL!
Tópico encerrado , respostas não são mais permitidas