Posts

Showing posts with the label Button

VB.NET: DoubleClick event for a Button

Spanish version / Versión en Español It's not everyday that you need to handle a double click event for a Button, but I happened to stumble upon a case. Suppose you have a Grid where the icons are buttons (in my case, those were image thumbnails, and so I intended to have the user double click a thumbnail in order to load the associated image). That led me to the need of handling the double click event for those Buttons. Now, .NET exposes the DoubleClick event for a Button, but it doesn't get fired for some obscure reason (Defined as a no-op?). Therefore, a workaround is to handle the more general MouseDown event instead, and consider the case where two clicks where made: Private Sub Button1_MouseDown(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles Button1.MouseDown If e.Clicks = 2 Then MessageBox.Show("The button was double-clicked.") End If End Sub ...

VB.NET: Evento DoubleClick para un Button

Versión en inglés / English version No es normal tener que manejar un doble click para un Button, pero yo me topé con un caso donde es necesario. Supongan que tienen una Grid donde los íconos son Buttons (en mi caso, eran thumbnails de Imágenes, y quería hacer que con doble click se seleccionara la Imagen correspondiente al thumbnail). Eso me llevó a la necesidad de manejar el doble click para un Button. Ahora bien, .NET ofrece el evento DoubleClick pero no se dispara. Lo que hacemos entonces es manejar MouseDown y considerar el caso particular en que se hicieron dos clicks: Private Sub Button1_MouseDown(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) _ Handles Button1.MouseDown If e.Clicks = 2 Then MessageBox.Show("The button was double-clicked.") End If End Sub Referencias: MSDN Forum