Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set my form active from global hotkey?

Tags:

c#

window

I have form named Form1. I set Hotkey Ctrl + G do:

Show();
Active();
TopMost = true;
TopMost = false;
TextBox1.Focus();

While I'm typing in Notepad, I press that hotkey, my Form1 appeared, like this: enter image description here

Both Notepad and Form1 have text cursor, but when continue typing, Form1.TextBox1 doesnt get input, but Notepad get.

But when open solution by Visual Studio and Debugging (F5), my Form1 get input, and Notepad doesnt.

Can you help me solve this problem? Thank you very much!

like image 563
Thanh Nguyen Avatar asked Dec 28 '25 04:12

Thanh Nguyen


1 Answers

Try calling ShowWindowAsync and SetForegroundWindow from your WinForms process on itself as outlined here:

http://weimenglee.blogspot.com/2007/01/programmatically-switch-to-another.html

It seems that notepad is still the active application.

like image 56
Eric J. Avatar answered Dec 30 '25 16:12

Eric J.