![]() Windows prevents apps from shoving their window into the user's face, you are seeing this at work. ![]() = //this is the key!!Īt times this method yields in a focus on the parent form (in cases where my desired form is a modal child form of its parent form) in such cases, just add this.Focus() to the last line. Private void button1_Click(object sender, EventArgs e) Static extern bool SetForegroundWindow(IntPtr hWnd) Never thought merely SetForegroundWindow() would do the trick. So I always used SetForegroundWindow() with chunks of other code. Going by heavy blocks of codes all over, I somehow felt this aint gonna be easy. At best I could get my form on top of all other forms, but without focus (going by Passant's method). I tried almost everything on internet (so sure about it :)). Notepad opens minimized, but focus will be still on notepad (something that sometimes we see in windows xp) and form will be out of focused. Why is it so difficult to merely get focus to a window, that too application's own window?ĮDIT: At best I can open the notepad minimized, but it still wouldn't give the focus to the form after trying all the above codes. SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle) Īnother lengthier solution got from here.Īll which still keeps the focus on notepad. ShowWindow(Process.GetCurrentProcess().MainWindowHandle, SW_RESTORE) Private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow) Private static extern int SetForegroundWindow(IntPtr hwnd) ![]() Public static extern IntPtr SetFocus(HandleRef hWnd) This.Activate(), this.Focus(), needless to mention ![]() I similarly (using the same Process.Start) open up MS Excel and Word but to get focus back to my form all I need to write is: this.Focus() īut quirk with Notepad: I open notepad (and all other processes like this) Process process = new Process() But I do want my application to maintain its focus. I open up a notepad from my program using Process.Start() but the new opened notepad covers the screen. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |