C#小知识

MessageBoxIcon的几种用法。 (全用Button做测试)

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 MessageBoxICon
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ButY和N_Click(object sender, EventArgs e)
        {
            MessageBox.Show("第一个框框", "点击过后", MessageBoxButtons.YesNo);
        }

        private void ButCancel_Click(object sender, EventArgs e)
        {
            MessageBox.Show("这部分是文字", "这一部分是标题", MessageBoxButtons.OKCancel);
        }

        private void Button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show("这部分是文字", "这一部分是标题", MessageBoxButtons.YesNoCancel);
        }

        private void ButPic_Click(object sender, EventArgs e)
        {
            MessageBox.Show("错误提示", "错误", MessageBoxButtons.YesNoCancel,MessageBoxIcon.Error);
        }

        private void ButWar_Click(object sender, EventArgs e)
        {
            MessageBox.Show("错误提示", "错误", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("错误提示", "错误", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
        }

        private void Button1_Click_1(object sender, EventArgs e)
        {
            MessageBox.Show("错误提示", "错误", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("错误提示", "错误", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

        }

        private void Button3_Click_1(object sender, EventArgs e)
        {
            MessageBox.Show("错误提示", "错误", MessageBoxButtons.YesNoCancel, MessageBoxIcon.None);
        }
    }
}

DialogResult的用法。 

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 TheValueOfMessageBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ButtHel_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("你好吗?", "你好", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
            if(result ==DialogResult.Yes)
            {
                MessageBox.Show("嗯,每天都要保持好心情哦!");
            }
            else if(result == DialogResult.No)
            {
                MessageBox.Show("怎么了?哪里不好啊?开心一点嘛,要相信明天什么事都会好起来的。");
            }
            else if(result == DialogResult.Cancel)
            {
                MessageBox.Show("你没有选择,我也不知道你开不开心,总之祝你前程似锦,百花盛开。");
            }
        }
    }
}

 

你可能感兴趣的:(c#学习记录)