Mono Gtk Window require focus for input - c#

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.

Related

limiting tabbing to a custom in-window message box

I have made a custom MessageBox for my application and it launches as a UserControl. I have two buttons inside it and I would like to allow users to press Tab to switch between Buttons. However, since it's a UserControl overlaying the content, Pressing tab more than twice makes the focus go in the background on elements that aren't supposed to be tabbed at.
I can't figure out a good idea how to prevent this, I've thought of making a method that will select all elements and make their IsTabStop values to false and then restore them later, but I think that would be more of a problem then a solution.
Is there a way around this to limit tabbing only to the UserControl?
I would also appreciate advice on working with the message box.. the whole messagebox is an async function that has an infinitive loop until the answer is given. Is there another way to stop the application until one of the message box options was selected?
Crowcoder's reference has lead to correct MSDN page where I found my solution:
dialog = new UCMessageBox("Are you sure you want to exit the application?", MBType.YesNo);
AppMessageBox.Children.Add(dialog);
KeyboardNavigation.SetTabNavigation(dialog, KeyboardNavigationMode.Cycle);
The key was to call .SetTabNavigation function and direct it to my dialog (custom UserControl for the message box) and setting the KeyboardNavigationMode to Cycle.
After closing the UC rest of the application continued normally regarding navigation.

Avoid Focus on Mainwindow when showing it

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.

Why is my Form on top when I hover over a GMap.NET control?

I have a GMap.NET control on my main form, and then I have a second form that will show when the user clicks on a button. The problem is, that when the user leaves the second window and hovers over the GMap control from the main form, the main form comes to the front. This does not happen when i hover over the rest of the main window with the second window on the front. Also I have another form that will show while the program searches for some data, and this one will also disappear when the user hovers over the map.
I hope I explained it well enough, basically when I hover over the map the main window comes to the front. And it does only happen when there is another form of my project in front of it, not when there is any other window like firefox or something in the front.
So my question is: why does this happen and can I change this behavior? Is it a standard of the GMap.NET control? I am using the Version 1.7.0.0 control btw.
you must use
GMap1.DisableFocusOnMouseEnter = true;
i added this code to my program and problem solved.
It would help to see some code as to how you are showing the forms, but it sounds like you are doing something like secondwindow.Show() instead of secondwindow.ShowDialog(), and then an event from GMap for OnEnter is doing a Focus().
Then, when you have the "other form" in front of it, it's opened in a way that will restrict access to the parent form (ShowDialog(), etc).

MessageBox doesn't show on mdi form after a long calculation

This is a very similar problem to This one, sadly that one was never answered either.
I have a MDI Main forum that hosts several children forms. One of them does a long calculation and throws an exception if an error occurs (all work is done on the same thread). I then try to inform the user of an error with an messagebox, however it doesn't appear (but steals focus from the MDI Main, so the application is completely unresponsive).
The beheviour changes slightly if I call Application.DoEvents() (evil I know, but this is a last resort thing). Then the forms remain completely active and the messagebox only appears after I change active application (Alt+Tab) to something else and then back again.
What can I do to make sure the messagebox will be visible? I have already tried passing both, active child and MDI Main as parameter to the MessageBox.Show method. It doesn't change the behaviour.
To clarify: the messagebox is a part of the child form, however at this point I am willing to show it in any way that doesn't break the application. The messagebox should be modal, but it should be visible so it can be acknowledged by the user.
I had the same issue. When pressed ALT the popup showed.
It turned out to be a LinkedLabel that had the AutoSize property to true. The LinkedLabel was inside a FlowLayoutPanel. When I set the LinkedLabel.Text property to String.Empty. The LinkedLabel constantly tried to resize, which was causing the GUI to be constantly busy.
When I turned off the AutoSize property and the GUI no longer had to recalculate the positions. The GUI was no free. And the popup showed.
There could be other controls that are behaving the same.
See also:
https://connect.microsoft.com/VisualStudio/feedback/details/116884
Is the MessageBox shown in the MainForm or as part of the ChildForms? If the MessageBox is in the child Forms maybe you could pass an event back to the MainForm and open the MessageBox there.
The problem is that messageboxes tend to be modal.
In this instance I think that you'd do far better to use a delegate or an event with a handler in your main MDI code. That way your main application displays the message boxes. You can easily redefined an EventArgsType if you wish to pass whatever information that you require.

Retain focus on a UI element, but click a button on a different dialog. WPF C#

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.

Categories

Resources