どっとねっとふぁん

C# Tips And Samples
in 検索

06.Windowの終了確認

最新の投稿は、投稿日時: 06-24-2005, 11:17 午前 投稿者: ono です。スレッドには 0 件の返答があります。
投稿のソート: 前へ 次へ
  •  06-24-2005, 11:17 午前 78

    06.Windowの終了確認

    Windowを閉じる際、メッセージボックスを表示して終了の確認を行うサンプルです。
    -------------------------------------------------------
    using System;
    using System.Windows.Forms;
    
    class HelloWorld : Form
    {
        private Button mybutton;
    
        public static void Main()
        {
            Application.Run(new HelloWorld());
        }
    
        public HelloWorld()
        {
            this.mybutton = new Button();
    
            this.SuspendLayout();
    
            this.Text = "Hello World!";
    
            this.mybutton.Location = new System.Drawing.Point(200, 200);
            this.mybutton.Text = "閉じるよ";
            this.mybutton.Click += new EventHandler(this.mb_Click);
            this.Controls.Add(mybutton);
    
            this.ResumeLayout(false);
        }
    
        private void mb_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    
        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            base.OnClosing(e);
            DialogResult dr = MessageBox.Show("終了していいですか",
                                              "終了確認", 
                                              MessageBoxButtons.YesNo);
            if(dr==DialogResult.No) e.Cancel = true;
        }
    }
    
    -------------------------------------------------------
    Windowを閉じる処理の中断の仕方、MessageBoxの使い方、イベントのオーバーライドのサンプルになってます。


    あおい情報システム株式会社
     小野修司(どっとねっとふぁん)
RSS ニュースフィードで参照
SkinName:iroha_CS2
Powered by Community Server, by Telligent Systems