You can write that code in FormClosing() and set the FormClosingEventArgs.Cancel property to true. I don't mean to be harsh, but the very first result for cancel formclosed[^] brings up the answer.
Cheers, Vikram.
"I will put my new found knolage to good use" - Captain See Sharp. "Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.