C# tray context menu not hiding when message box - c#

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.

Related

Click outside wpf window without losing focus

I was wondering if there is a window property, for a wpf application, that disables any actions outside of the window. For example, when you open a message dialog and click outside of it, the message dialog background flashes. Kind of saying you can't do any actions outside of the message dialog untill you click the 'OK' button. I want that implemented in some windows that I open in a program i'm developing but can't seem to find any info on it. Looking for ways on how i might approach this.
Try ShowDialog() instead of Show()
Opens a window and returns only when the newly opened window is closed.
Window childWindow = new Window();
childWindow.ShowDialog();
Note that it will prevent clicks only on parent window(s). Clicks on other applications or Desktop can't be prevented by the Dialog.

Minimize prompt dialog on button click - Bot framework C#

I am a learner using Bot-framework. I am trying to find a way to minimize a prompt dialog for instance one with "Yes" and "No" options. My intention is that when one clicks "Yes", the prompt dialog disappears and also when he clicks "No".I have seen sample bots with the functionality but i just cant figure out how it is implemented. Any help?
Sadly you can't minimize the PromptDialog items once they are clicked.
But instead you can use SuggestedActions which are buttons displayed at the bottom of your window and disappear once they are clicked.
See sample in the documentation: https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-add-suggested-actions?view=azure-bot-service-3.0
And you can have a look to what it will render here: https://docs.botframework.com/en-us/channel-inspector/channels/WebChat?f=SuggestedActions&e=example1

Inject custom system menu item and handler into newly opened windows

What I want to do:
I want to create a custom menu item (along with minimize, maximize, close, etc.) when a user right-clicks on a window's title bar. Additionally, I want the user to be able to click on my menu item and trigger my code. Also, I want to do this for every newly opened windows. For example, when the user opens up a new notepad window and right clicks on its title bar, he/she will see: Restore, Move, Maximize, Minimize, Foo (my menu item), Close. Once they click on "Foo", my code gets called.
What I have so far:
I am using SetWinEventHook to hook the EventObjectCreate event. I am also following this guide to insert my own menu item (via GetSystemMenu and AppendMenu).
My question:
So now I can successfully inject my own menu item onto newly created windows, but nothing happens when the user clicks on the item. How do I register my function to this menu item when it gets clicked?
P.S. I'm doing this in C# using Pinvoke, not sure if this matters.
You have to hook the windows' window proc (also known as subclassing the window) and handle the WM_SYSCOMMAND message. You check the wParam parameter and call your function if the menu item selected is your custom item.
You're going to run into interesting problems. See, for example, Subclass a native application from C# and Subclassing a external window in C# .NET.
It can be done, but it's not simple.
You might also be interested in http://www.codeproject.com/Articles/3234/Subclassing-in-NET-The-pure-NET-way.

SetWindowPos changes context menu size

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.

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.

Categories

Resources