在C#中 怎样实现把再任务栏右键关闭程序这个功能给隐藏掉 就是实现点击右键不能关闭应用程序C#右键关闭程序 ,隐藏

解决方案 »

  1.   

    这个恐怕要重写WndProc(ref Message m)了吧?
      

  2.   

    在WinFrom程序把FormBorderStyle设置为None,用以隐藏标题栏。
    这样有程序在任务栏上,点右键的时候没有关闭菜单。
      

  3.   

    http://hi.baidu.com/wcsjsdn/item/919915c23f8f0624ee4665bb
    随便一搜就能找到
      

  4.   

    thx,个人喜欢第三个方法using System.Runtime.InteropServices; //禁用关闭按钮需要引用这个
    /***************************禁用关闭按钮需要***********************/
            [DllImport("USER32.DLL")]
            public static extern int GetSystemMenu(int hwnd, int bRevert);
            [DllImport("USER32.DLL")]
            public static extern int RemoveMenu(int hMenu, int nPosition, int wFlags);
            const int MF_REMOVE = 0x1000;
            const int SC_RESTORE = 0xF120; //还原 
            const int SC_MOVE = 0xF010; //移动 
            const int SC_SIZE = 0xF000; //大小 
            const int SC_MINIMIZE = 0xF020; //最小化 
            const int SC_MAXIMIZE = 0xF030; //最大化 
            const int SC_CLOSE = 0xF060; //关闭
            /******************************************************************/
    private void Form_Load(object sender, EventArgs e)
            {
                /***************************禁用关闭按钮需要***********************/
                int hMenu = GetSystemMenu(this.Handle.ToInt32(), 0);
                RemoveMenu(hMenu, SC_CLOSE, MF_REMOVE);
                /******************************************************************/
            }
    这两种方法都是很平常的方法,调用API函数,这种有时在利用第三方控件后,方法失效。那么,还是推荐第一种方法。
      

  5.   

    我需要托盘菜单,只是想把右键菜单给屏蔽掉 该怎样做 程序是用WPF写的
      

  6.   


     private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
           if (e.CloseReason == CloseReason.UserClosing)
           {
                 e.Cancel = true;
           }
    }
            
    e.CloseReason还有其它关闭的情况的,你根据你的情况选择哪种情况不关闭,就把e.Cancel设为true就会不关闭的了!