2016-04-26 22 views
0

MessageBoxButtons.YesNoを作成しようとしていますが、formclosingのダイアログを作成できますが、これをEXITボタンの1つにしたいと考えていました。私は問題がxButton3_Click()である理解されるように、そうMessageBoxエラーSystem.EventArgsに定義が含まれていません

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

ボタンを使用しています。 Cancelプロパティはありません。ちょうど 'else'をドロップしてください。 –

答えて

0

:私は

ここに私のコードだボタン3

e.Canel = trueを宣言し、このエラーを取得しています。変更する:

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

関連する問題