0

One of my application has one notice c# form that needs to be brought to front every time new notice received, regardless of the status of the form.

And additionally, we don't want the notice form to steal focus when brought to front.

I tried to use topMost and maximize/minimize the form, all failed.

Any ideas?

What I have tried so far:

1 Does not bring the form to front at all

Form theForm = new Form();
。。。 // Add new notice in the form content
Show();
BringToFront(); 

2 Bring to front but focus is grabbed

Form theForm = new Form();
。。。 // Add new notice in the form content
TopMost=true
Show();
TopMost=false

3 Bring to front but focus is grabbed

Form theForm = new Form();
。。。 // Add new notice in the form content
WindowState = FormWindowState.Minimized;
Show();
WindowState = FormWindowState.Maximized;
Community
  • 1
  • 1
FaceBro
  • 787
  • 2
  • 13
  • 29
  • Failed how? In bringing to the front or in not grabbing the focus? – GolezTrol Jan 26 '17 at 08:30
  • @GolezTrol By fail, I mean failed to accomplish what I described, that's failed to brought to front while at the same time don't get focus when I did manage to bring it to front. – FaceBro Jan 26 '17 at 08:38
  • @Steve I just cannot share any code due to confidential concerns.. – FaceBro Jan 26 '17 at 08:39
  • What you describe sound similar to the On-Screen Keyboard (stay on top but don't steal focus). This can be achieved by hooking up WndProc and invoking the [SetWindowPos](http://www.pinvoke.net/default.aspx/user32.setwindowpos) method with the `SWP_NOACTIVATE` Flag. (In the constructor, upon activation, etc. basically every time windows gives you focus you tell it to f-off) – Manfred Radlwimmer Jan 26 '17 at 08:42
  • @Steve I do agree with your point, but I think my requirement is clear and straightforward, so is code really necessary ? – FaceBro Jan 26 '17 at 08:47
  • 2
    @guardian It is customary to show what you have tried beforehand. Sometimes existing attempts are almost complete and only need small adjustments. Simply stating your requirements and expecting code in return is generally considered bad form and leads us to believe that you have tried nothing and want someone else to write your code for you. You mention that you have tried `TopMost` and that *"all failed"*, which is not much of an effort. I recommend you get comfortable with P/Invoke and check out the link I posted in my previous comment. – Manfred Radlwimmer Jan 26 '17 at 08:51
  • @ManfredRadlwimmer That's a good point, and I will add more details soon. – FaceBro Jan 26 '17 at 08:54
  • 1
    [Opening a WinForm with TopMost=true but not having it steal focus?](http://stackoverflow.com/questions/3729899/opening-a-winform-with-topmost-true-but-not-having-it-steal-focus) – GolezTrol Jan 26 '17 at 09:36

0 Answers0