Blend Presentation Materials From Columbia SC Updated 11 Aug 2007

During testing of my incrememting textbox that functions like the one in Microsoft Blend, I had on occasion noticed a fly in the ointment.  What would happen was that the textbox would continue to increment even though the mouse was no longer down or near the textbox in question.

This morning I’m reading from Charles Petzold’s book, “Applications = Code + Markup” and was reading about the CaptureMouse method on UIElements.  Turns out, this method is exactly what I need to ensure that textbox functions correctly.

 You can download the updated code in the below presentation.

The basic problem was that under certain circumstances, the textbox was not receiving the OnMouseUp event.  This is the event where all clean up was being done.

So to ensure clean up always gets performed, I’ve added in the counter part to CaptureMouse which is OnLostMouseCapture.  By placing clean up code in OnLostMouseCapture, I ensure that the textbox clean up routines always run, even if the control never receives the OnMouseUp event.

Have a great day,


Just a grain of sand on the worlds beaches.

Comments are closed.


Get every new post delivered to your Inbox.

Join 255 other followers