Frage

I haven't been able to find an example containing this functionality, and either i missed it in the documentation or it's not there.

I have a fullscreen GUI program, and when a user is required to type in a number, a calculator window popup has to appear in the center of the screen. The user types a number and clicks on enter, or hits cancel to continue past the window.

The problem is clicking on the fullscreen window behind the calculator brings that window to the front and hides the calculator without the intended entry being completed, which could get annoying for the user.

I guess the functionality I'm trying to create is what happens in most text editors/IDE's when you press the Open File button. Let me know if you want to see code, it's just two separate Window classes at the moment.

War es hilfreich?

Lösung

The Present() function of the Window object brings that particular window to the front. So adding a FocusOutEvent listener on the window you wish to keep in front like:

windowObj.FocusOutEvent += (obj, args) => windowObj.Present();

will work.

The alternative to this (and the better way) is to set the Modal property of the window to true.

If you've stumbled across this and you were looking for a popup window that suspends whatever called it to wait for input, see this question:

gtk# thread for window

You basically use the Dialog class instead of Window and add your elements to the ActionArea of the Dialog.

Hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top