Winforms App. .Net 3.5.
I need to set the focus from my C# application to the user’s desktop (almost like simulating a mouse click on the desktop).
Can someone please show me how to do this with C#? I just want to set focus on the desktop so the focus is no longer on my application but I want to do this from within my application.
Edit: An answer below works by setting the focus to the desktop, but it minimizes all the open windows on the user’s desktop.
Is there a way I can maybe set the focus to the next open window on the desktop instead? I just want to get the focus off of my application (without minimizing my application or hiding it). I just want to move focus to somewhere else. Maybe the desktop was not the best choice if it will minimize all the user’s open windows/applications.
You can add this COM object in your project:
Microsoft Shell Controls And Automation
And then just call:
This will minimize all the windows and then focus the desktop. Otherwise, if you have your window non-full screen then you can simulate the mouse click using:
You can calculate coordinates by looking at your window startup location plus height/width and select a available space (that will be the desktop indeed).