2
votes

I develop a window form application that shows message like msn alert at the right corner of desktop. I set form's topmost property to true but it steals other application's focus while I work on them. I don't want application steal the focus that is annoying. How can I solve this problem . Any suggestion?

Best regards.

1

1 Answers

4
votes

Override the Form's CreateParams and ShowWithoutActivation properties, like this:

protected override CreateParams CreateParams
{
  get
  {
    CreateParams baseParams = base.CreateParams;

    // WS_EX_NOACTIVATE = 0x08000000,
    // WS_EX_TOOLWINDOW = 0x00000080,
    baseParams.ExStyle |= ( int )( 
      Win32.ExtendedWindowStyles.WS_EX_NOACTIVATE | 
      Win32.ExtendedWindowStyles.WS_EX_TOOLWINDOW );

    return baseParams;
  }
}

protected override bool ShowWithoutActivation
{
  get { return true; }
}