Closing a form that was opened by ShowDialog()
<p>I have a winform application where I've written my own little color picker that will only display system colours. It's basically a <code>TableLayoutPanel</code> with a bunch of smaller panels added to it, to which I just set the background color. </p>

<p>Pretty simple:</p>

<p><a href="https://i.stack.imgur.com/cH4gQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cH4gQ.jpg" alt="enter image description here"></a></p>

<p>Now I'm opening this form for with:</p>

<pre><code>using (frmColourWindow colourPicker = new frmColourWindow (Cursor.Position.X, Cursor.Position.Y, findingPriority))
{
    colourPicker.ShowDialog();
    if (!colourPicker.SelectedColor.IsEmpty)
    {
        pnlColor.BackColor = colourPicker._SelectedColor;
    }                    
}
</code></pre>

<p>and closing it with by setting the <code>DialogResult</code> when the user has clicked on one of the color panels.</p>

<p>This all works pretty good, the only thing I can not manage to get right is by closing the form when it loses focus (E.g. when the user clicks somewhere else or starts typing). I've had a look at the <code>Deactivate</code>, <code>LostFocus</code>, and <code>Leave</code> events. Just can't seem to get those events to fire when I want them to. Maybe I'm missing something obvious?</p>