Taskbar right click application context menu [JumpList] - c#

How can I make a menu on the right click in the taskbar using Windows forms?
Something like this:

You can simply add contextMenuStrip from toolbox to form1. then go to form1 propertires -> contextMenuStrip . and the select the recently added contextmenuStrip1. You can add buttons to the contextMenustrip.
You should add at least one button in order to get the menustrip on rightclick.

Related

How do I make a form TopMost from a different existing form?

I have a navigation menu to select the settings for the main form. How would I go about making the whole application TopMost from a different existing form.
Picture 1 shows the settings form
How would I be able to change TopMost from the Menu Settings section
I am using panels to display the change between forms.
(Assuming this is WinForms) I think I'd do it by bind to a setting.
On the form you want to be topmost open the form in the designer, click the form background so the Props grid shows props for the form, then expand Application Settings and click the 3 dots next to Property Binding
Drop down next to TopMost and choose New
Call it IsTopMost ...
Then in some code (anywhere, in any form, anywhere.. Such as this button click handler..) change Properties.Settings.Default.IsTopMost
private void button1_Click(object sender, EventArgs e)
{
Properties.Settings.Default.IsTopMost = !Properties.Settings.Default.IsTopMost;
}
If you run this, and then click that button on form2, form 1 will pop to top and be topmost. If you click it again, it will toggle off. If you have some settings form2, and you bind a checkbox to this value, by the same process, then when you click the checkbox on form2, form1's TopMostness will follow the check state of the checkbox on form2.
Regardless how you change that bool in Properties.Settings.Default.IsTopMost, it will influence Form1's TopMostness

Having trouble in selecting ToolStrip button in Windows Form C#

I have this toolstrip on my windows form. When double clicking on ToolStrip button it gives me
my designer view:
my code view:
I'm wanting to have a button click event on every button and have a click event like on the image below.
their designer view:
their code view:
it seems like I can't click on the button directly, rather it selected the whole toolstrip instead.
Judging by the icon in the top left, this is netcore, or net5. Some things in winforms designer on these platforms are still very wonky and toolstrip related things seem to be one of them..
Change to winforms on .net framework if you can, or add your click event handlers in code if you can't:
write the name of your button in code, followed by .Click +=
Accept the suggestion to insert a method for you by pressing tab
It's because you doubled click the whole ToolStrip not the buttons on the ToolStrip

Add a function to contextMenu item at notifyIcon

I use an contextMenu1 and an notifyIcon1 for the app. When the app is in Tray Icon and I will press Right Click, a menu will appear.
The code is this (I add only 2 items for test):
contextMenu1.MenuItems.Add("View");
contextMenu1.MenuItems.Add("Exit");
notifyIcon1.ContextMenu = contextMenu1;
In this moment, in the menu I see only the items that don't do enything.
How I can add a function, like private void exit() to the contextMenu1.MenuItems.Add("Exit"). When I will pres the Exit item, to close my app (example).
There is a second parameter to Add that lets you assign an eventhandler:
contextMenu1.MenuItems.Add("Exit", ExitApplication);
// or using an anonymous method:
contextMenu1.MenuItems.Add("Exit", (s,e) => Application.Exit());
In the first example, ExitApplication is your event handler:
private void ExitApplication(object sender, EventArgs e)
{
// exit..
}
You can also construct a MenuItem first and assign the eventhandler in the constructor, if you prefer.
I am assuming that you have a Windows Form and a Button (name : btnShowMessage). When you dobule click on the button you will get a event handler "btnShowMessage_Click". Also you have a notificationIcon with ContextMenuStrip attached with it. You have even an menu option in the context menu strip (name : btnContextOpenMsg). With The following steps you can use to achieve your requirement.:
Below image is for your clear understanding :
Go to Context Menu --> select btnContextOpenMsg
Press F4 to open the property sheet
Click on "Events" button on top of the property sheet
Click on "Click" and expend the drop down beside the click event by clicking "..."
Select the btnShowMessage_Click from the drop down.
Compile you code after saving it.
You should see your notification (system tray) menu when you minimized your app.
Click on the "Show Message" option so that it will execute the same function as for the button.

Window Menu "Selection" Event in C#

Is there an event that fires on a mdi child form when said form is selected in the "Window" menu of an mdi parent? I tried just detecting focus but I need to be able to know when the menu item is clicked even if the child window to which it corresponds is minimized.
You can try the Activated event. It fired when the form is on top

WinForms context menu - not open in certain parts / detect underlying control

I have a .NET 2.0 Windows Forms application. On this app there is a Form control with a Menu bar and a status bar. Also there's a ListView on this form.
If I add a context menu to this form, the context menu will open when the user right clicks any part of the form, including the menu bar and the status bar.
How can I prevent the context menu from opening when the click happened on the menu bar / status bar? I want it to open only when clicking the "gray area" of the form.
If the click happened above a control on this form (for example, on the ListView), how can I identify this? I'd like to know if the user right clicked above the gray area or above the ListView, so I can enable/disable some menu items based on this.
After you've placed your Statusbar at the bottom and MenuStrip at the top,
Set ContextMenuStrip on your form to None
Place a standard Panel in the middle (between MenuStrip and StatusStrip) with the Dock property set to Fill.
Set the ContextMenuStrip property on your Panel (instead of on the form).
And place the ListView and all other controls that should go into the form in the Panel
Eg
~~~~~~~~~~~~~
menustrip
~~~~~~~~~~~~~
Panel. Dock=Fill. ContextMenuStrip=yourContextMenu.
~~~~~~~~~~~~~
StatusStrip
~~~~~~~~~~~~~
I found the answer:
Point clientPos = this.PointToClient(Form.MousePosition);
Control control = this.GetChildAtPoint(clientPos);
This should give the underlying control that was clicked on the Form, or null if the click was on the gray area. So we just need to test for the type of the control on the Opening event of the context menu. If it's MenuStrip, ToolStrip or StatusStrip, do e.Cancel = true;.

Categories

Resources