Home All Groups Group Topic Archive Search About
Author
6 Jun 2006 8:28 AM
Philipp
Hi NG,

Is there a way to know which control just lost focus when clicking on a
button?
(other than keeping an object variable which is set when a control loses
focus)?

Thanks in advance!

Greets
Philipp

Author
7 Jun 2006 12:21 PM
Phill W.
Philipp wrote:

> Is there a way to know which control just lost focus when clicking on a
> button?

I've used this in a custom Button class.

Class myButton
    Inherits Button

    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)

       If Not (Me.FindForm Is Nothing) _
       AndAlso Not (Me.FindForm.ActiveControl Is Me) _
       Then
          Me.Focus()
       End If

       MyBase.OnClick()

    End Sub

End Class

I haven't tried, but you /might/ be able to do the same sort of thing in
the event handler for an "ordinary" Button's Click event.

HTH,
    Phill  W.