我在MSDN上找到了一个线程,它显示了如何将项添加到winform标题栏的上下文菜单中.不幸的是,它没有显示如何使用自定义菜单项注册事件,我一直无法弄清楚如何做到这一点.下面是一个示例应用程序,可以将其复制并粘贴到新的Windows窗体应用程序中.如果有人可以为我完成样品,我将不胜感激.谢谢
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
IntPtr hMenu = GetSystemMenu(Handle, false);
if (hMenu != IntPtr.Zero)
{
var menuInfo = new MENUITEMINFO
{
cbSize = (uint) Marshal.SizeOf(typeof (MENUITEMINFO)),
cch = 255,
dwTypeData = "Test Item",
fMask = 0x1 | 0x2 | 0x10,
fState = 0,
fType = 0x0
};
InsertMenuItem(hMenu, 0, true, ref menuInfo);
DrawMenuBar(Handle);
}
}
[DllImport("user32.dll")]
static extern IntPtr GetSystemMenu(IntPtr hWnd, bool …Run Code Online (Sandbox Code Playgroud)