C# 最小化到系统托盘的实现(二)

下面要实现的就是这个对话框:

要求:点击主面板关闭按钮时,弹出这个对话框. 其中有个选项"Do not show this dialog again".

本来想用系统对话框作的,可是没有这个选项,所以就定义一个Form来做.

大家一起来讨论一下大家要设计这样一个对话框的思路吧。语言要求:C#。

1. 新建一个WindowsForm, 在主面板里生成一个对象

QPanCloseDialog NewCloseDialog = new QPanCloseDialog();

2. 定义一个值来确定是否显示这个对话框.

 public static bool boolShowCloseDialog = true;

3.定义退出策略.

 //退出策略

private bool DecideToExit()

{

      if (boolShowCloseDialog == true)

      {

            this.NewCloseDialog.ShowDialog();//显示模态窗口

 

            if (boolCancelCloseQPan == true)

            {

                  return true;

            }

            else

            {

                  if (boolCloseQPan == true)

                  {

                        return false;

                  }

                  if (boolCloseQPan == false)

                  {

                        this.QPan_MiniMizedToTuoPan();

                        return true;

                  }

            }

      }

      else if (boolShowCloseDialog == false)

      {

            if (boolCancelCloseQPan == true)

            {

                  return true;

            }

            else

            {

                  if (boolCloseQPan == true)

                  {

                        return false;

                  }

                  if (boolCloseQPan == false)

                  {

                        this.QPan_MiniMizedToTuoPan();

                        return true;

                  }

            }

      }

      return true;

}

4.关闭窗口

//所有关闭Form的出口

 

private void MinimizedToTuoPan(object sender, System.Windows.Forms.FormClosingEventArgs e)

{

      if (boolCloseFromExitMenu == true)

      {

            e.Cancel = false;

      }

      else

      {

            e.Cancel = DecideToExit();

      }

}

5.设定关闭对话框

 //加载时取消“Do not show this dialog againt“.

private void QPanCloseDialog_Load(object sender, EventArgs e)

{

      RememberSelection.Checked = false;

}

public bool ExitFromButtom = false;

//点击“Exit”按钮

private void ExitDialogExit_Click(object sender, EventArgs e)

{

      this.ExitFromButtom = true;

      QPan.boolCancelCloseQPan = false;

      QPan.boolCloseQPan = true;

      this.Close();

}

//点击“Minimize”按钮

private void ExitDialogMinimize_Click(object sender, EventArgs e)

{

      this.ExitFromButtom = true;

      QPan.boolCancelCloseQPan = false;

      QPan.boolCloseQPan = false;

      this.Close();

}

//点击“Cancel”按钮

private void ExitDialogCancel_Click(object sender, EventArgs e)

{

      this.ExitFromButtom = true;

      QPan.boolShowCloseDialog = true;

      QPan.boolCancelCloseQPan = true;

      QPan.boolCloseQPan = false;

      this.Close();

 

}

//点击"X"关闭按钮

private void QPanCloseDialog_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)

{

      if (this.ExitFromButtom == false)

      {

            QPan.boolShowCloseDialog = true;

            QPan.boolCancelCloseQPan = true;

            QPan.boolCloseQPan = false;

            RememberSelection.Checked = false;

      }

}

//选择"Do not show this dialog againt"

private void RememberSelection_CheckedChanged(object sender, EventArgs e)

{

      if (RememberSelection.Checked == true)

      {

            QPan.boolShowCloseDialog = false;

      }

      else if(RememberSelection.Checked == false)

      {

            QPan.boolShowCloseDialog = true;

      }

}

 

。。。。。。

具体还有一些细节就不详述了

posted on 2009-06-22 11:35  曾令理  阅读(1009)  评论(0编辑  收藏  举报

导航