I have a .Net 4 application with two windows in WPF 4:
One uses the WS_EX_NOACTIVATE style to prevent gaining focus.
The other is a basic Window.
The "no-activate" window behavior is appropriate as soon as I do not select the basic window (it doesn't gains the focus). But when the basic window is selected, the "no-activate" window can be focused... and gains it when the user clicked on it.
It is as if WPF considered two windows of the same application had the right to give focus even if they are not supposed to.
This behavior does not happen if both windows are WS_EX_NOACTIVATE.
Have you ever been faced with this problem?
I have read this: WPF in Visual Studio 2010 – Part 3 : Focus and Activation, but does not solve it.
Edit: I have been able to get around by using a Popup as a base class for my no-active Window. However, I don't want to have a Popup. Why !? The popup never receives the focus: does someone know why / how ? How can I reproduce this behavior to a Window ?
I try to step into Popup / Window code, but it is not very clear !
Thanks !
Try also giving it the WS_EX_TOOLWINDOW.
http://www.daniweb.com/software-development/csharp/threads/273724/a-form-that-doesnt-steal-focus#
OK. I partially solved the problem.
The Window already got the focus if it is directly selected, but it is not focused when a component of the window is selected.
Just add :
Focusable = false;
to any WPF controls contained in the Window and they will never been focused even if the previous focus is a Window of the same Application.
Related
How do I prevent the main window (where I write something in the textbox) from losing focus?
The application has a couple of pop-up windows that sometimes show up and it prevents me from continuing to write text in the main window (and I have to click back to it).
Thanks for any advice.
You have to create those popup windows as modeless window.
Refer microsoft sample here
I'm having a problem where a winforms application I wrote is always in front of other applications.
Its TopMost property is set to false and yet whenever I click on anything else on my computer (Google Chrome, Windows Explorer, etc) the winforms application stays in front of them, albeit grayed out. This means that to effectively use other applications while my winforms app is running, I have to minimize it.
I'm wondering if there's a way to change it so that it works like a normal application, where it goes behind other windows that are clicked on without minimizing or closing it
Pics:
Upon opening the app
Upon clicking on VS
As you can see, clicking on visual studio does gray out the app, but the app still shows in front of VS. This is the same behavior with all other windows.
Here are the properties of the form:
And the rest of the properties:
Turns out that one of the methods does programmatically change the value of TopMost to true, so that was causing my problem. Thanks to fujiFX for pointing that out as a possible reason
I'm working on some C# application to help myself learn C# a bit. I've been searching for a solution, but I can't seem to find one.
When my application minimizes, it shows a notifyicon in the system tray. When I right click it, a context menu pops up on the mouse. However, for each level of the menu and submenu, a blank window pops up on the taskbar until I exit that submenu or the contextmenu.
I don't know why, and I'd like to. I'd also like to know how to prevent that from happening.
Edit
Also, in Visual C# Studio 2010, when debugging, is there a way to determine exactly which form/part of the code I've focused on, so that I could click one of those windows to see what exactly it is?
How are you showing the ContextMenu? I suspect you are calling ContextMenu/ContextMenuStrip.Show(x,y) directly. That will cause it to show in the taskbar.
Instead, assign your ContextMenu/ContextMenuStrip to the ContextMenu/ContextMenuStrip property of your NotifyIcon rather than manually showing it in the mouse click handler. If it is used as part of ContextMenu/ContextMenuStrip property, it won't show in the taskbar.
I have a forms app and when it starts up I would like it to give focus to a particular text box. While I was initially developing I just whacked all the controls straight on the form and the focus command worked fine.
The app is near ready and I put some splitcontainers on the form just to hold the controls in neatly defined areas using their Dock properties. Now a completely different read only control gets focus on startup and the app seems to ignore my command that the focus should go to this one textbox. Does any one know why this might be?
You can try this :
splitContainer1.Focus();
splitContainer1.ActiveControl = textBox1;
If it doesn't works please post your focus code here.
Sorry because i didn't write a comment but i don't have the privilege yet.
I am having a strange problem. I have a C# .NET 2.0 application and a context menu. When you right click on the application, the context menu shows up and one of the items on the menu is Options. When you click options, I have an OptionsDialog form that shows up (using ShowDialog() method). The problem is, on Windows XP, the focus keeps going away. If I click on the options form, its gains focus for a second, but then loses it again! I have tried everything. On the Deactivate event, I call this.Focus() but that doesn't seem to make a difference. I also tried making the window topmost, but still doesn't work.
Another wierd thing is that this problem only seems to happen on XP. I tried it with Vista and Windows 7 and it works perfect. XP is doing something wierd though. Anyone have any thoughts on how to solve this?
A person here seems to have the same problem: http://forums.devshed.com/c-programming-42/c-form-won-t-focus-on-control-535596.html
Is that anything like what's going wrong with you? If you have a default button or a control that is the first tabStop value that also happens to be disabled when the form starts up, it could be the cause of the problem.
Check any disabled controls on the form, and make sure the default button and the first tab stop controls are both enabled. (Hint: Default button should usually be 'Cancel' on a modal form, and it should always be enabled.)
If you find out which window has the focus afterwards, maybe it gives you a clue what's going on.
This little demo app from 1997 will help you: http://www.microsoft.com/msj/0397/Win32/Win320397.aspx