Buenas noches, tengo unos metodos para mover botones en tiempo de ejecucion y un menu strip que agrega otro boton, que cuando lo agrega asigna de nuevo a todos los controles que sean botones, que se puedan mover, entonces los demas que ya estaban asignados
cuando los muevo vibran o desaparecen.
Public _x, _y, x, y, segundo As Integer
Public Movimiento As Boolean
'-----------------------------------------------MOVER BOTONES---------------------------------------------
Private Sub Control_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
_x = e.X
_y = e.Y
If e.Button = MouseButtons.Left Then
If TypeOf sender Is Button Then
Movimiento = True
End If
End If
End Sub
Private Sub Control_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If Movimiento Then
If CType(sender, Control).Left = 0 Then
CType(sender, Control).Left = 1
Else
CType(sender, Control).Left = e.X +
CType(sender, Control).Left - _x
End If
If CType(sender, Control).Top = 0 Then
CType(sender, Control).Top = 1
Else
CType(sender, Control).Top = e.Y +
CType(sender, Control).Top - _y
End If
End If
End Sub
Private Sub Control_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Movimiento = False
End Sub
Public Sub AsignarEventos(ByVal _Controles As Control)
Dim Controles As Control
For Each Controles In _Controles.Controls
AddHandler Controles.MouseDown, AddressOf Control_MouseDown
AddHandler Controles.MouseMove, AddressOf Control_MouseMove
AddHandler Controles.MouseUp, AddressOf Control_MouseUp
AsignarEventos(Controles)
Next
End Sub
en AsignarEventos habia echo algo asi:
Dim ExisteBoton As Boolean = False
For Each nombres As String In BotonesEnEvento
If nombres = Controles.Name Then
ExisteBoton = True
End If
Next
If Not ExisteBoton Then
BotonesEnEvento.Add(Controles.Name)
AsignarEventos(Controles)
End If
para controlar si ya lo habia echo en el boton pero sale del metodo.
gracias un saludo