Many Thanks tetrastes,
Your change did indeed fix the problem. The program no longer does infinite paints, and no longer hangs when the user closes it.
I am posting the fixed project, in case anyone cares.

But, if you'd like a version that draws cards, I posted in the games sub forum a few days ago.
cheers
S.