A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 黑马李蒙 中级黑马   /  2013-4-22 11:57  /  1784 人查看  /  8 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

怎么才能让我单击右上角的关闭 按钮不起作用? 每次单击它的时间程序不见了?怎么才能让它不起作用,单击没反应。谢谢!

8 个回复

倒序浏览
你这是啥?控制台?winform?还是啥玩意~~
回复 使用道具 举报
陈帅 发表于 2013-4-22 12:00
你这是啥?控制台?winform?还是啥玩意~~

我用的是VS2010  wpf窗口
回复 使用道具 举报
wpf 我不清楚是什么  
但我可以给一下 winform 程序中让窗体的 “关闭” 按钮失效的代码 给你参考一下
在 formclosing 事件里写一行代码  e.cancel = true;  就可以让它失效;但是要用任务管理才
能把该程序关闭;
  1. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  2.         {
  3.             e.Cancel = true;
  4.         }
复制代码
希望对你有帮助
回复 使用道具 举报
额,WPF真心没有研究过,
不过windows下的程序都是基于消息机制的,比如按下一个字母,windows就将这个“按键”消息发给当前的窗口,窗口会处理这个消息,点击鼠标左键、最小化窗口……都是发送了一个消息。
1)窗口右上角的X,实际上就是个按钮,找到处理这个按钮的函数,让它什么也不干,直接返回。
2)“关闭窗口”实际上是发送了个消息,(右上角那个X就是发送这个消息),找到处理这个消息的函数,直接返回就好。
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
下面是我百度的。。。。WPF
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (MessageBox.Show("确定关闭窗口吗?","",MessageBoxButton.OKCancel) == MessageBoxResult.OK) return; //直接返回,关闭窗口            
            e.Cancel = true;
        }
回复 使用道具 举报
如果你是windows系统的话,多半是卡住了,ctrl+shift+esc或者ctrl+zlt+del调出资源管理器,找到对应的进程并结束,然后重新打开程序,如果还是不行的话,直接重启系统。
回复 使用道具 举报
你可以试试把关闭按钮的事件属性设置为false
回复 使用道具 举报
本帖最后由 张伟86 于 2013-5-1 13:29 编辑

Closing函数中设置事件Cancel=true就可以取消按钮的关闭属性,但是你需要设置其他方法关闭窗口释放资源了。
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;

  14. namespace WpfApplication1
  15. {
  16.     /// <summary>
  17.     /// Window1.xaml 的交互逻辑
  18.     /// </summary>
  19.     public partial class Window1 : Window
  20.     {
  21.         public Window1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.         //Closing函数中设置事件Cancel的属性值
  26.         private void Window_<font color="#ff0000">Closing</font>(object sender, System.ComponentModel.CancelEventArgs e)
  27.         {
  28.             e.Cancel = true;         
  29.         }        
  30.     }
  31. }
复制代码
回复 使用道具 举报
肖川 发表于 2013-4-22 12:57
如果你是windows系统的话,多半是卡住了,ctrl+shift+esc或者ctrl+zlt+del调出资源管理器,找到对应的进程 ...

你把楼主的意思理解错了!在理解一遍......
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马