"Peter de Vroomen" <peterv[at][spamblock]jaytown[dot]com> wrote in message
news:42b834a4$0$32070$e4fe514c@news.xs4all.nl...
> Hi,
>
> I have a floating EditBox (a TextBox on a borderless Dialog) over a
> ListView. I wish to capture the mouse events so I can detect if a user
> clicked outside of the EditBox. I show the floating EditBox as modal, so
> the
> underlying form with the ListView is deactivated. When I click outside the
> EditBox, I need to remove it and reactivate the underlying form.
>
> I therefore set the Capture property of the EditBox to True. On MouseDown,
> I
> check if I clicked inside or outside the EditBox, and deactivate the
> floating EditBox when the click was outside (remember, it's actually a
> TextBox on a Dialog, so I just return a DialogResult of Cancel, and the
> underlying form is reactivated). This works fine.
>
> However, when I click INSIDE the EditBox with the left mouse button, the
> Capture property is reset to False by the .NET Framework. From then on any
> click outside the EditBox results in a *ping* because the mouse click is
> sent to the underlying (deactivated) form instead of captured by my
> EditBox.
>
> No matter what I try, the Capture property is reset to False *after* the
> MouseUp event finishes. It actually doesn't matter where I click, the
> Capture property is simply forced to False after the MouseUp event
> finishes.
> Apparently the framework itself is resetting the Capture property after
> the
> MouseUp event returns.
>
> So I thought to override the TextBox class and the OnMouseUp event. In the
> OnMouseUp event, I force the Capture property to True. Like this:
>
> Public Class ctrlCustomTextBox
> Inherits TextBox
>
> Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
> MyBase.OnMouseUp(e)
> Capture = True
> End Sub
> End Class
>
> But to no avail, Capture still gets reset after the sub OnMouseUp returns.
>
> I then chose to not call MyBase.OnMouseUp(e), risking all sorts of
> unexplained behaviour. But that had absolutely no effect either.
>
> So, I have reached the end of my knowledge. Anybody have an idea what I
> can
> do?
>
>
> --
> Regards,
>
> Peter de Vroomen
> Software Engineer
> Jaytown
>
http://www.jaytown.com >
>
>