I need a window that does not activate when I click on it but is should elsewhere react normal. By normal I mean if there is a button on it and I click on the button it should execute the click and call the click function ( or event handle or what so ever). So it should be a normal window except that it shouldn't get activated when you interact with it.
I know you can do this with a message filter or hooks but is there any window style that does this automatically?
this is for windows.
thanks!
Have you tried the WS_EX_NOACTIVATE extended window style?
A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window.
To activate the window, use the SetActiveWindow or SetForegroundWindow function.
Otherwise, if that doesn't do what you want, you will need to handle the WM_MOUSEACTIVATE message and return MA_NOACTIVATE.
Related
I have a window that I open up with ShowDialog(). The window will open in te center of my previous window. To close this window with background click I found the solution:
protected override void OnDeactivated(EventArgs e)
{
base.OnDeactivated(e);
Close();
}
The solution only works (look in picture the bracket on bottom) if I click outside any of my windows. But if I click on my Window(right bracket) I only get that sound and nothing happens(OnDeactivated does not proc).
Any Ideas?
Because ShowDialog prevents you from activating dialog's parent window, hence no activation change is made, hence no proccing.
You could use Show, as in non-modal way to show your dialog form, in case you don't "wait" on the calling code for the dialog to finish with some result.
If you do, there are workarounds, like a callback solution, or a how to close a WPF Dialog Window when the user clicks outside it link that #BWA pointed out.
I need to move focus from popup window to parent window without closing popup window. For example Find and replace dialog-box behavior in Excel.
how to achieve this in WPF C# coding.
Call .Show() instead of .ShowDialog() when you displaying your popup. If you want to keep it on top - set popup window 'TopMost' property to true.
In a WPF application I'm working on, I have a MenuItem with two items in it. When the MenuItem is clicked, it takes keyboard focus and opens its submenu. When the MenuItem is clicked again, the submenu is closed and for some reason, the main window takes keyboard focus. I need the MenuItem to keep focus.
I have been told that in certain other situations, the main window may be given keyboard focus - for instance, if a control has keyboard focus and IsEnabled or IsVisible becomes false. In which situations does this happen? I've been Googling like crazy but haven't found any information about this.
As far as I can tell, this is the expected behavior. WPF Menus are focus scopes by default, so any control within the menu that receives focus won't change the main logical focus of the window.
Also, certain WPF controls will sometimes call Keyboard.Focus(null); (e.g. Button does this when clicked). This call has the effect of returning the keyboard focus to the main logical focus. I suspect this is also happening when a menu is closed.
Try disabling the focus scope on the menu: <Menu FocusManager.IsFocusScope="False">
When the menu item receives the keyboard focus, and it's not in any focus scope, it will gets the main logical focus. This means the Keyboard.Focus(null) call will keep the focus on the menu item. Jowever, this will also prevent commands in the submenu from returning the focus to the non-menu window content, so routed commands won't be able to find their target.
See "For What was FocusScope Designed?" in Using the WPF FocusScope.
I am relatively new to C#. I have a window with buttons. If the window is out of focus and I click on a button the first time, the first click grabs focus for the window and all subsequent clicks will perform their respective actions.
Is there a way to execute the event associated with the button instead of grabbing focus?
It sounds like you are describing how ToolStrips operate, which does not fire a click event unless the application has the focus.
A work around is to use your own ToolStrip and let the mouse activation give the control the focus, which in turn will then let the button fire it's click event:
public class ToolStripIgnoreFocus : ToolStrip {
private const int WM_MOUSEACTIVATE = 0x21;
protected override void WndProc(ref Message m) {
if (m.Msg == WM_MOUSEACTIVATE && this.CanFocus && !this.Focused)
this.Focus();
base.WndProc(ref m);
}
}
Rebuild your solution and you should see a ToolStripIgnoreFocus control available in your tool box. Try adding that to your form and then add your tool buttons accordingly.
This is how most Windows apps work - the app needs to have focus before it can receive click events.
As far as I know, you've described an inherent Windows behaviour and as such it could be impossible to do.
An alternative is to harness 'Always on top' style of windows app which is explained here:
How to make a window always stay on top in .Net?
This is normal windows behavior. Something that I don't think you can override (so that the click event fires, but doesn't bring your app to the foreground, and active state).
If you don't want to bring focus to the window, but still want to provide some 'interaction' with the window itself, try keyboard hooks or hotkey events. Examples:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/2622427d-1e15-4f30-b01d-57b0ba054f5c
Using global keyboard hook (WH_KEYBOARD_LL) in WPF / C#
Low-level Keyhook
http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html
Is there a winforms event that fires when the user switches from a form to another window? I.e. Not through minimizing, but just by clicking on another window. How can I detect when the form becomes inactive? Thanks!
Form.Deactivate