我找到了解决方案,但是有一个问题 [英] i find the solution ,but there is aproblem

查看:73
本文介绍了我找到了解决方案,但是有一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我在这里找到解决方案:
但是我需要传递此代码(class_Exit ex = new class_Exit();
ex.exituni();)来统一关闭时通过关闭图标或按钮关闭显示的消息框

 受保护的 覆盖  void  OnFormClosing(FormClosingEventArgs e)
 { base  .OnFormClosing(e);
      如果(例如,CloseReason == CloseReason.WindowsShutDown)返回// 确认用户要关闭
   开关(MessageBox.Show(" 确定要关闭吗?" 关闭" ,MessageBoxButtons.YesNo))
    {
   案例 DialogResult.
      e.Cancel =  true ;
         break ;
   默认:
          break ;
   
  }
         } 

解决方案


检查此

  class  ClsClose
    {
        表格frm =  Form();
       公共 ClsClose(表格_frm)
        {
            frm = _frm;
        }
       公共 无效 CloseForm()
       {

           frm.Close();
       }
    }
          // 表格
        私有 无效 button1_Click(对象发​​件人,EventArgs e)
        {
            ClsClose cls =  ClsClose();
            cls.CloseForm();
        }



 .Close();
// 
Application.Exit(); 



最好的问候
M.Mitwalli


 // 图标事件
     私有 无效 Icon_Click(对象发​​件人,EventArgs e)
        {
            exitClass ex =  exitClass();
            ex.exituniversal();
        } 


为什么要编写用于处理关闭按钮的代码,只需将控制箱"属性设置为false.


Hii,everyone

i find the solution here :
but i need to pass this code ( class_Exit ex = new class_Exit();
ex.exituni();) to unify the message box that will appear when close by close icon or button close

protected override void OnFormClosing(FormClosingEventArgs e)
 {     base.OnFormClosing(e);
      if (e.CloseReason == CloseReason.WindowsShutDown) return; 
     // Confirm user wants to close  
   switch (MessageBox.Show(this, "Are you sure you want to close?", "Closing", MessageBoxButtons.YesNo)) 
    {  
   case DialogResult.No:   
      e.Cancel = true; 
        break;  
   default:
         break;
   
  }
         }

解决方案

Hi ,
Check this

   class ClsClose
    {
        Form frm = new Form();
       public  ClsClose(Form _frm )
        {
            frm = _frm;
        }
       public void CloseForm()
       {

           frm.Close();
       }
    }
          //Form
        private void button1_Click(object sender, EventArgs e)
        {
            ClsClose cls = new ClsClose(this);
            cls.CloseForm();
        }



this.Close();
//or 
Application.Exit();



Best Regards
M.Mitwalli


//Icon Event
     private void Icon_Click(object sender, EventArgs e)
        {
            exitClass ex = new exitClass(); 
            ex.exituniversal();
        }


why ur writing code for to handdle close button ,just set form ''control box'' property set to false.


这篇关于我找到了解决方案,但是有一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆