DialogResult的使用方法

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _2014050904DialogResult
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        public string message = "You did not enter a server name. Cancel this operation?";
        public string caption = "No Server Name Specified";
        public MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        public DialogResult result;

        public void show()
        {
            //显示MessageBox.
            result = MessageBox.Show(this, message, caption, buttons);

            //如果点击的是"YES"按钮,将form关闭.
            if (result == DialogResult.Yes)
            {
                // Closes the parent form.
                this.Close();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            show();
        }
    }
}

你可能感兴趣的:(c#)