Dialog Box loses focus in Windows XP - c#

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

Related

Winform always stays in front of other applications

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

WPF application with several windows including a non active: focus issue

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.

How can I prevent my C# application from opening new windows during context menu?

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.

Is there a way to avoid the taskbar getting focus when running a form?

I am building a small program I want to hover over the other programs, and I use TopMost to handle this quite well.
Now my issue is that once I work in my tool, it also brings the Windows Taskbar forward, whereas I would like not to pull it to the top.
Is there a way to address this?
An acceptable workaround would be to "restore focus" on previous active program, is there an easy way to do this? (like Alt + Tab)
Have you tried just setting the ShowInTaskbar property for your form to False? That'll cause your form to not show up in the Windows taskbar.
For the 'restore focus' part of your question, you can use the form.activate method easily enough.

Keep form on desktop at all times (No Win+D effects)

I'm working on a project in which I need a form to stay on the desktop at all times. This would mean that it should still be showing even if a user clicks Win+D to hide/show desktop.
If anyone uses Rainmeter, they will know how meters stay on the desktop despite clicking on the show desktop key.
I really don't mind how to do it, as long as it works. I've looked through hundreds of examples but half of them don't work..
Maybe someone could help me out.
Thanks in advance.
I fired up C# and created a Windows Forms application. I set the forms' TopMost property to True, and its MinimizeBox property to False.
When I run the app, the Window is always on top, even if I use Win+D or click Show Desktop.
I got the idea from here: What is the difference between Minimize All and Show Desktop?
If you want something to stay on the desktop, you should put it on the desktop. Look at using Windows Gadgets which can do what you want.

Categories

Resources