I'm showing a form using Form.ShowDialog()
, in this Form I have override void WndProc(ref Message m)
because I want to close this form when user click outside Form area.
private const int WM_NCACTIVATE = 0x0086;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCACTIVATE:
if (_canClose) // when user click outside form, close form
this.Close(this, EventArgs.Empty);
break;
default:
break;
}
base.WndProc(ref m);
}
This code work as I expected, but one minor problem, Windows play DING
sound every time user click outside Form area, I want to "mute" this DING
when this code processed.
UPDATE
I managed to make this Form work as I want to, using advice from Hassan Mujtaba
, but I still wonder how to mute this DING
if I use Form.ShowDialog
.
Using Form.Show() instead of Form.ShowDialog() will solve the problem.