Jump to content
leoretorico

[Resolvido] Button para limpar campos de texto

Recommended Posts

leoretorico

Boa tarde amigos!

Estou criando uma classe (Buttom) para limpar campos de texto de formulários

Estou usando o código abaixo.Mas não sei como usar o evento click deste botão.

Imports System.Drawing
Imports System.Windows.Forms

Public Class Buttom
Inherits Button

#Region "Members"

Public mArguments() As String

#End Region

#Region "constructor"
Public Sub New()
	MyBase.New()
	ReDim mArguments(0)
End Sub
Public Sub New(ByVal sPathExe As String)
	MyBase.New()
	ReDim mArguments(0)
End Sub

#End Region

#Region "Actions Events"

Sub limpaCampos(ByVal objeto As Object)
       Dim oObj As New Object
       With objeto
           For Each oObj In .Controls
               If TypeOf oObj Is MaskedTextBox Or _
               TypeOf oObj Is ComboBox Or TypeOf oObj Is TextBox Then

                   oObj.Text = Nothing
                   oObj.Focus()
               End If
           Next
       End With
   End Sub

Private Sub ButtonColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
limpacampos '( QUAL CÓDIGO POSSO USAR AQUI)
End Sub

#End Region

#Region "Color Events"
Private Sub ButtonColor_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseHover
	Me.BackColor = Color.Blue
End Sub

Private Sub ButtonColor_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
	Me.BackColor = Color.LightSkyBlue
	Me.UseVisualStyleBackColor = True
End Sub

#End Region

End Class

Edited by ribeiro55

Share this post


Link to post
Share on other sites
emanuelx

tu tens de introduzir o objecto na função, a melhor maneira é usar textbox tradicionais.

limpacampos(nome_do_objecto_que_queres_limpar)

mas não precissas disso se os objectos forem estáticos, se os objectos forem estáticos usa textbox1.text=""


com calma e sem stresses

Share this post


Link to post
Share on other sites
vikcch

ola, tens de criar mais um membro

Public mFrmName As Object

passa-lo no construtor

Public Sub New(ByVal frmName As Object)
    MyBase.New()
    Me.mFrmName = frmName
    ReDim mArguments(0)
   End Sub

chamar a sub no evento click

    Private Sub ButtonColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
    limpaCampos(mFrmName) '( QUAL CÓDIGO POSSO USAR AQUI)
   End Sub

e passas o me quando instanciares da classe

mas tambem acho que não vale a pena uma classe só para limpar os controlos...

para que serve o mArguments e o sPathExe ?

Share this post


Link to post
Share on other sites
He B TeMy

Eu já tentei usar limpaCampos(Me) e deu erro .

Talves se postares qual o erro te possamos ajudar.

Edited by He B Te My

Share this post


Link to post
Share on other sites
nelsonr

Pode ser algo assim: (não testei)

Private Sub ButtonColor_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Dim parentControl As Control = Me
'
While (Not IsNothing(parentControl.Parent))
	parentControl = parentControl.Parent
End While
'
limpaCampos(parentControl)
End Sub

O objectivo é encontrar o control pai de todos os controls e usar esse control na chamada da função para limpar

Edited by nelsonr
  • Vote 1

Share this post


Link to post
Share on other sites
leoretorico

Pode ser algo assim: (não testei)

O objectivo é encontrar o control pai de todos os controls e usar esse control na chamada da função para limpar

Pode ser ? Era isso que eu precisavaaaaaaa !!! Muito obrigado!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.