SetWindowPos changes context menu size - c#

If a context menu is open in the program being resized/repositioned it's size and position are also changed, is there any way around this?
Example

Popup menus operate their own modal message loops. Key-presses are handled by the menu. Mouse clicks either invoke menu items, navigate sub-menus, or close the menu.
In short, there's no way for the user to invoke a move or size of a window whilst a menu is running its modal message loop.
Because of this, the designers of the system don't care what happens to the menu in the scenario that you describe because there's no supported way for that scenario to occur. It's happening for you because, I guess, you have a timer that calls SetWindowPos on the window that owns the menu.
The way around this is for you not to move or size windows whilst they have popup menus open.

Related

close a WPF Dialog Window when the user clicks outside it

GoodDay, Here i want to minimize the WPF Window, While user clicking outside of the window.
I can easily minimize the window by this code
mywindow.WindowState= WindowState.Minimized;
but i want minimize the window at the time of clicking outside of the window.
i searched about that. But i can only got the output of various events like, FocusChanged,MouseMove,MouseDown like that. those are not solve my issue
You could use the Deactivatedevent. Have a look at the MSDN for further information.
A window is deactivated (becomes a background window) when:
A user switches to another window in the current application.
A user switches to the window in another application by using ALT+TAB or by using Task Manager.
A user clicks the taskbar button for a window in another application.

Preventing multiple notifyIcons when not actually closing application

I want to be able to keep just one notifyIcon without others crowding up my taskbar when I 'Snooze' my form. The design is such that it should not be able to be closed (outside of closing down the process) so the controlbar has been removed. It can only be hidden by pressing the provided button at which point it minimizes to the taskbar, but for some reason when I test it a few times I end up with a taskbar full of icons that don't disappear until I hover over them.
I'd appreciate any advice

Hide console window, not the taskbar button

I am in a need of hiding the console window, which I quickly resolved by P/Invoking ShowWindow. However, the call hides the console window as well as the taskbar button of the console window. I need the taskbar button to remain visible. I am not, however, looking for a way to minimize the console window. Clicking the taskbar button show not do anything. I tried to use SetWinEventHook and hide the window every time it was activated, but to no avail, as the window calling this function must run message loop in order to receive the events (and my console window didn't, no matter if I set OutOfContext or InContext flag).
Is there a way I can make my console application run, show itself in taskbar, then hide itself (or never show itself in a first place) and just keep running with no window but taskbar button visible?
The normal way to get a button on the taskbar is to create a visible unowned top-level window. So that's no use to you. One possible alternative is to use ITaskbarList::AddTab to add a button. I don't know whether or not this will do anything for an invisible window. Either way you'd need to run a message loop for your window. Even if you could do this the net result would not feel very nice for the user.

Change Minimize Animation

I have an application that minimizes to the system tray. That all works well, the problem is that when minimized the animation goes towards the left side of the screen.
Is there a way to change it so the animation goes towards the tray?
No. This animation is handled by Windows, and since you are invoking the Minimize routine on the window, Windows will automatically animate the window into the location where the window's button is on the taskbar. If you're looking for a "quick solution", there isn't one.
The most you could do is change the window's behavior so that when it's minimized, it actually closes instead. This would prevent the fly-down animation into the taskbar, and Windows would perform the window close animation instead, which may look more consistent with your application design. A lot of other tray icon programs handle it this way.
If you really want to change the window's animation, you will need to override any Windows window management features with your own, that way when the window is "minimized" (or closed), you can animate your window to appear to move into the notification area on the right.

C# tray context menu not hiding when message box

In my application I have context menu which is associated with tray icon of the application, when user click on About menu item, it display the message box. Message box is still visible, user right click again on tray icon, menu pop up, user click somewhere else than context menu should disappear, but it didn't, it is still displayed.
That's a bug. Probably in Windows, the MSDN Library documentation for TrackPopupMenu documents a very similar problem. I don't see an obvious workaround, other than avoiding using MessageBox. Create a little form to be your About box. Display it with the Show() method.
You could use SendKeys.Send("{ESC}");
in the trigger event when the user clicks somewhere else.

Categories

Resources