Get control events created? Visual Basic

0

I have a problem with which I have battled hours and I hope someone can help me:
I am working on a system which clients will handle, remove the edges of the form to avoid being closed by customers joking or such, then I added an "Exit" button where clicking will create 2 controls: 1 label that gives indications and a EditText where the password is entered to exit, the case is that when creating these controls, their events are not defined in the code, and I want to know how to do that, I refer to events such as those of the "Button1_Click" button and such, I attach the code of the button that creates these controls:

Dim txtsalir As New TextBox  
Dim lblsalir As New Label  
Dim resDest As Size = System.Windows.Forms.SystemInformation.PrimaryMonitorSize  
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles btnSalir.Click 'A esta linea me refiero  
 If btnSalir.Text = "Cancelar" Then  
  Me.Controls.Remove(txtsalir)  
  Me.Controls.Remove(lblsalir)  
  btnSalir.Text = "Salir"  
ElseIf btnSalir.Text = "Salir" Then 
  txtsalir.Font = New Font("Arial", 42, FontStyle.Regular,,GraphicsUnit.Pixel)  
  txtsalir.TextAlign = HorizontalAlignment.Center  
  txtsalir.PasswordChar = "*"  
  txtsalir.Width = resDest.Width / 2  
  Dim centrarw As Integer = resDest.Width / 2 - (txtsalir.Width / 2)  
  Dim centrarh As Integer = resDest.Height / 2  
  txtsalir.Location = New Point(centrarw, centrarh)  
  lblsalir.Text = "Ingresar contraseña para cerrar el sistema"  
  lblsalir.AutoSize = True  
  lblsalir.TextAlign = HorizontalAlignment.Center  
  lblsalir.Font = New Font("Arial", 42, FontStyle.Regular, GraphicsUnit.Pixel)  
  lblsalir.Location = New Point(centrarw, centrarh - 50)  
  Me.Controls.Add(txtsalir)  
  Me.Controls.Add(lblsalir)  
  txtsalir.Focus()  
  btnSalir.Text = "Cancelar"  
End If  
End Sub  
    
asked by Carlos Alberto Marrufo 06.07.2018 в 06:45
source

1 answer

1

You must run the AddHandler statement to add to the event that you need of those controls a function to execute, in the following way:

AddHandler Control.Evento, AddressOf FuncionAEjecutar

Example with btnSalir :

AddHandler btnSalir.Click, AddressOf Button1_Click

You can do this for all the controls you want by always indicating the function they should execute.

    
answered by 06.07.2018 / 10:24
source