how can I set focus to a textview and window in GTK - c#

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.

Related

How do I show/activate the text cursor in open document? [C#, EnvDTE]

I'm trying to set the cursor in an open document, but it doesn't show. I can see that the line is "marked" and I can "navigate" the lines, but the cursor is not shown, and thus I'm not able to write anything. Also it seems like the document doesn't really fully load, since guidelines and the navigationmap is not shown either.
Which makes me believe that the focus isn't being set completely inside the document.
I have confirmed that the focus indeed is not set in the document in the window, since If I have the output window focused before, it's still focused after the window.Activate() method has been called.
I've used the common way of opening the document through ProjectItem.Open(Constants.vsViewKindCode), activating it, and using the TextSelection.GotoLine(1,false) method.
This correctly shows the document and sets the line correctly, but I have to manually click inside the document for the cursor to appear.
The code I have:
Window window = projItem.Open(Constants.vsViewKindCode);
window.Activate(); <----- this does not focus the window.
TextSelection textSelection = window.Document.Selection as TextSelection;
textSelection.GotoLine(1, false);
I want to not have to manually click inside the document for it to load completely and for me to be able to write in it.
Hope someone can help me.
Oh well, another issue I had to solve by myself... Two for two. I guess people don't know that much in here like I'd hoped. Oh well.
Anywho, I discovered that if you use DTE.ItemOperations.OpenFile(path); and nothing else,
the file will receive focus correctly, just like it should have when you use .Activate().

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.

Mono Gtk Window require focus for input

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.

C#/WPF, how to make a window (created with Window.ShowDialog()) title bar blink when clicking its parent window (like MessageBox does)?

I'm trying to create a custom MessageBox by using a WPF Window that is called with ShowDialog().
So far, I've managed to implement everything, except for one thing.
As you know, when you use MessageBox.Show("text"); you cannot set the focus or click the parent window (the one that called the MessageBox). If you do try to click the parent window, the MessageBox will blink briefly in order to alert you that you must close if first.
Windows created with Window.ShowDialog();, however, do not show that behavior. In fact, while you cannot set the focus to the parent window, the child (called with ShowDialog()) will never blink briefly.
My question is, is there any way to implement that in WPF? I've been searching for an answer but I must admit, I am stumped.
Thanks everyone!
You need to set the Owner of the modal window correctly, e.g. using the following code from within the owning window:
Window win = new SomeModalWindow();
win.Owner = this;
win.ShowDialog();
You would have to set Owner property of the child Window to the parent Window. See the MSDN Documentation here.

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