I'm currently working on a popup program in wpf that gets hidden either by this.hide(); or MainWindow1.WindowState = WindowState.Hidden and "pops up" using MainWindow1.WindowState = WindowState.Normal;
My problem is, that I don't want the Mainwindow to gain any keyboard focus.
So whatever program has the keyboard focus, when the popup gets shown, it should keep it.
I just want it that way, so people don't type entire emails in the not handeling Popup, just because they didn't notice it popping up.
Edit:
I'm not trying to keep focus in any my own program windows but in other windows programs (e.g. Outlook)
Edit2:
Here is a screenshot from my Program, just to clear obscurities about the usage of the PopUp class.
Edit3: Maybe it's possible to set the keyboard focus back to the programm that was focused before?
so people dont type entire emails in
I would recommend that you set the main page controls, or their container, Enabled property to false when the popup is running and reverse when it is not. Hence focusing the user to the popup until its acknowledged.
If you purpose is to show a notification form, check that component: Windows Forms Toolkit NotificationForm
The solution is (as it seems) too easy, all you need to do is:
MainWindow1.Showactivated = false;
this.Show();
This will show the MainWindow while the focus is kept on whatever program had the focus before the MainWindow appeared.
Related
I am having some very frustrating issues with my WPF window. The design I was going for is:
When the user minimizes the window it will minimize to a system tray icon (hide the window and icon on start bar). When the user right clicks on the icon, a context menu will show up with options and one of them will say open, which will open the app (show window again / unhide window agian). The user could also double click the icon as well.
Pretty simple right?
I have no issues minimzing to the task bar, I simply do the following on the closing event of the window:
e.Cancel = true;
this.Visibility = Visibility.Collapsed;
However, I am having issues properly restoring the window. I simply do this on the context menu click or icon double click event:
this.Visibility = Visibility.Visible;
this.Activate();
The issue is that the window is once again on the start bar with its icon but it is behind every single window the user has open. I want it so when the user goes to open the window it will be the top most window. I do not always want it to be the topmost, just only when they want to make it visible again.
I have tried many things like setting the show activate on the window to true, waiting a second after making it visible to then activate the window, activating the window multiple times (worked a few times but was maybe 1 out of 10 tries), etc..
I don't think showing / hiding a window should be this annoying and I am not really sure what I am doing wrong.
Any help is appreciated, thank you.
Only after posting this did I realize, the application minimizes first before hiding. When I show the window, it was showing as minimized.
After knowing this issue I was able to fix the issue. This may help others who do decide to hide the window after minimizing.
EDIT
Here is the code I used to hide the window (this is called after the event fires for state changed [minimized]):
Application.Current.MainWindow.Visibility = Visibility.Collapsed;
Application.Current.MainWindow.WindowState = WindowState.Normal;
You will notice I set the window state back to normal after I hide it. Even though the window is hidden and not being rendered it will in memory restore the window location / size.
Then when I want to see the window again I just do:
Application.Current.MainWindow.Visibility = Visibility.Visible;
Which will show the window just fine!
Hopes this helps someone out there!
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.
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.
I tried
textview.GrabFocus();
but it does nothing. Is there any way to do that? (Please try to answer this time instead of telling me to use google - I have tried and failed, thanks).
I also tried the same for a window:
// searchbox is a GTK window, which was initialised on load of this form
searchbox.Show();
searchbox.GrabFocus();
// this function will set focus to text box
searchbox.setFocus();
the main window in this case open a new window and is supposed to make this new window focused, and certain text box in this window focused - it doesn't work though and I have no idea why, full source code:
the window I am opening: https://github.com/pidgeonproject/pidgeon/blob/gtk%23/Forms/ScriptEdit.cs
the window from which I am opening: https://github.com/pidgeonproject/pidgeon/blob/gtk%23/Forms/Main.cs#L520
okay so given that this is probably very uncommon problem that was related to configuration of my application I don't expect anyone to solve it, however I found out what the problem was.
The window I created was of type
window.Hint = Gtk.WindowTypeHint.Utility
And for some reason unknown to me, it's not possible to set focus for this window. It may be even bug inside of GTK, but changing this to Normal did work.
I want a form to be shown modal every time it is opend. Since I can not change the way it is created and opend. I wondered if it is possible to make the form stay on top from within the forms class.
One opportunity is the TopMost property. This works in general, but if I display the form while the main thread is waiting for it to close, the form will stay on top even if I change the application(to a browser for example). So no matter where I am, the form is still displayed.
Another issue which I came across is that in some cases it is adopted by the parent form which then might block other windows or popup messages.
I was thinking about a hook to the OnLostFocus event to get it on top again, once the focus is lost, but I'm not sure if that is a good idea ...
Any helpful thoughts about it?
Edit
Due to the comments I will extend my description, Here is the real use-case
We are using the Devexpress's SplashScreenManager which is able to show a certain form as a WaitForm. Since the WaitForm is not intended to be shown modal(see on the Support Center), we are looking for a way to do so.
We can not change the way the form is shown, because this is done through the SplashScreenManager. The WaitForm is shown both from the main thread, as well as from certain backgroundworker.
So this is only about an own form of ourselfs, displaying it within our own application.
Use:
TopLevel = true;
This will do exactly what you want; be topmost as long as the main form is shown and hide if the mainform is hidden by another window.
You can set the owner of your splash form to your main form explicitly without using .Show(owner).
splashForm.Owner=mainForm;
splashManager.Show(splashForm);
We did not want the TopMost property since it works on windows level and covers other windows too (for example the browser).
In the end I hooked up on the focus event of the window to make sure the window is always on top.
I am developing a touchscreen friendly app that also includes a virtual keyboard. My virtual keyboard is in its own window, allowing it to be moved around. The problem is that when I click on a key on the keyboard the text box on the main application window no longer has focus. The switch from the main application being the active window to the keyboard dialog being the active window means that any field on the main window no longer has focus. How can I get around this?
I tried setting the keyboard window as not focusable. Though this is probably good to set, it did not solve my problem.
You could just return focus to the original window asynchronousely:
public static void BackgroundFocus(this UIElement el)
{
Action a = () => el.Focus();
el.Dispatcher.BeginInvoke(DispatcherPriority.Background, a);
}
But this is not ideal, because the original window caption would flicker when losing focus...
Why don't you use Popup instead?
Check out the function SetForegroundWindow() ,
I have used this long time back some where in my project
May be this may help you
Using a Popup, as already suggested, seems like a good solution. As for your custom window, try setting the Window.ShowActivated to false.