2016-04-26 97 views
0

我試圖做一個MessageBoxButtons.YesNo,我知道你可以做一個對話框formclosing,但我想爲我的EXIT按鈕之一。我得到這個錯誤在那裏我將Button3MessageBox錯誤System.EventArgs不包含定義

這裏是我的代碼中聲明e.Canel = true

using LOGINPAGE.Models; 
using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace LOGINPAGE 
{ 
    public partial class FACULTY : Form 
    { 
     public FACULTY() 
     { 
      InitializeComponent(); 

      SetFloorsToDropDown(); 
     } 

     private void FACULTY_Load(object sender, EventArgs e) 
     { 
      // TODO: This line of code loads data into the 'roomInfoDataSet2.Table' table. You can move, or remove it, as needed. 
      this.tableTableAdapter1.Fill(this.roomInfoDataSet2.Table); 
      // TODO: This line of code loads data into the 'roomInfoDataSet1.Table' table. You can move, or remove it, as needed. 
      this.tableTableAdapter.Fill(this.roomInfoDataSet1.Table); 


     } 

     private void xButton5_Click(object sender, EventArgs e) 
     { 

      Floor.SelectedIndex = -1; 
     } 

     private void xButton2_Click(object sender, EventArgs e) 
     { 

      this.Close(); 
      Application.Exit(); 
     } 

     private void xButton3_Click(object sender, EventArgs e) 
     { 
      DialogResult dialog = MessageBox.Show("Do you want to Exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); 
      if (dialog == DialogResult.Yes) 
      { 
       Application.Exit(); 
      } 
      else 
      { 

       e.Cancel = true; 
      } 

     } 

     private void checkBox1_CheckedChanged(object sender, EventArgs e) 
     { 

     } 

     private void xButton1_Click(object sender, EventArgs e) 
     { 

     } 

     private void Floor_SelectedIndexChanged(object sender, EventArgs e) 
     { 
      dataGridView1.Rows.Clear(); 

      if (Floor.SelectedItem.ToString() != "SELECT FLOOR") 
      { 
       foreach (var item in roomInfoDataSet1.Table.Where(x => x.Room_Number.Substring(0, 1) == Convert.ToString(Floor.SelectedValue))) 
       { 
        string[] row = new string[] { item.Room_Number, Convert.ToString(Floor.SelectedValue) }; 

        dataGridView1.Rows.Add(row); 
        dataGridView1.ClearSelection(); 
        dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true; 
        dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1; 
       } 
      } 
     } 

     private void SetFloorsToDropDown() 
     { 
      List<DropDownModel> floorList = new List<DropDownModel>(); 

      floorList.Add(new DropDownModel() 
      { 
       Id = 0, 
       Name = "SELECT FLOOR", 
      }); 

      floorList.Add(new DropDownModel() 
      { 
       Id = 1, 
       Name = "1st Floor", 
      }); 

      floorList.Add(new DropDownModel() 
      { 
       Id = 2, 
       Name = "2nd Floor", 
      }); 

      floorList.Add(new DropDownModel() 
      { 
       Id = 3, 
       Name = "3rd Floor", 
      }); 

      floorList.Add(new DropDownModel() 
      { 
       Id = 4, 
       Name = "4th Floor", 
      }); 

      floorList.Add(new DropDownModel() 
      { 
       Id = 5, 
       Name = "5th Floor", 
      }); 

      floorList.Add(new DropDownModel() 
      { 
       Id = 6, 
       Name = "6th Floor", 
      }); 

      Floor.DataSource = floorList; 
      Floor.DisplayMember = "Name"; 
      Floor.ValueMember = "Id"; 
     } 



     private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 
     { 

     } 

     private void xButton1_Click_1(object sender, EventArgs e) 
     { 

     } 



    } 
} 
+2

您正在使用一個按鈕。沒有取消屬性。只要放下'else'即可。 –

回答

0

所以,我的理解這個問題是在xButton3_Click()。將其更改爲:

private void xButton3_Click(object sender, EventArgs e) 
{ 
    DialogResult dialog = MessageBox.Show("Do you want to Exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); 
    if (dialog == DialogResult.Yes) 
    { 
     Application.Exit(); 
    } 
} 

您不需要使用else。只是保持原樣。如果用戶選擇「是」,則應用程序將關閉,否則不需要採取任何措施。

+0

是的,我得到它的工作!現在,有沒有辦法做到這一點打開不同的窗口?我猜這會是一樣的?就好像如果消息框裏說的是**,你想打開這個窗口嗎?**並且他們碰到是或不是 – Programmer23

+1

我建議更新你的答案代碼以向他展示他應該做的事情。 – Mikanikal

+0

@Mikanikal是的,你是對的。謝謝 – Marusyk

相關問題