Muchas veces necesitamos saber si el control ya existe en el formulario; ya sea para crearlo o para modificar sus propiedades.
Código VB6:
'Este ejemplo llama a la función existe, para saber si puede modificar el control
Sub Show ()
if existe ("Pers_Control") then
gForm.Controls("Pers_Control").text = ""
end if
end sub
Function existe (aControl)
On Error Resume Next
Set lcontrol = gForm.Controls(cstr(aControl))
If lcontrol Is Nothing Then
existe = false
Else
existe = true
End If
End FunctionCódigo C#:
// Este ejemplo llama a la función ExisteControl para saber si puede modificar el control
public void Show()
{
if (ExisteControl("Pers_Control"))
{
(gForm.Controls["Pers_Control"] as ITextoUsuario).Text = "";
}
}
private bool ExisteControl(string nombreControl)
{
return gForm.Controls[nombreControl] != null;
}¿Le ha sido útil este artículo?
¡Qué bien!
Gracias por sus comentarios
¡Sentimos mucho no haber sido de ayuda!
Gracias por sus comentarios
Sus comentarios se han enviado
Agradecemos su esfuerzo e intentaremos corregir el artículo