Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, August 25, 2014 11:53 AM
C# Disable or Hide close button in context menu of Task bar
All replies (4)
Monday, August 25, 2014 2:15 PM ✅Answered
I don't believe that is possible as the menu below the divider is system generated. However your application can choose to ignore close requests by handling the appropriate close message.
Michael Taylor
http://blogs.msmvps.com/p3net
Monday, August 25, 2014 2:29 PM
I think the context menu is registry driven.
http://www.thewindowsclub.com/remove-click-context-menu-items-editors
So you could programmatically change the users' registry.
Hope that helps
Please don't forget to up vote answers you like or which help you and mark one(s) which answer your question.
Tuesday, August 26, 2014 5:55 AM
Hi AK Samaiyar,
Did you mean you want to disable or hide "Close Window" button in context menu of Task Bar? In C# .NET Farmwork, as far as i know, there is no direct methods to help you implement. Maybe you need call windows API or modify the registry or any other way. But i did not find.
In addition, Here is an article about Programming the Task Bar in Win7 as below, please help take a look.
Programming the Task Bar in Windows 7 with WPF 4, Part Two – Jump Lists
Hope it helpful for you
Have a nice day!
Kristin
Tuesday, January 5, 2016 7:46 PM
Add the following library
using System.Runtime.InteropServices;
Declare the following as class level variable
const int MF_BYPOSITION = 0x400;
[DllImport("User32")]
private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
[DllImport("User32")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("User32")]
private static extern int GetMenuItemCount(IntPtr hWnd);
In the Form_Load() event, write the following code
private void Form1_Load(object sender, EventArgs e)
{
IntPtr hMenu = GetSystemMenu(this.Handle, false);
int menuItemCount = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);
}