C#程序設計(十七)----一個顯示文本,一個顯示圖片,單擊任意一個顯示提示框

* 程序的版權和版本聲明部分
* Copyright (c) 2012, 煙臺大學計算機學院學生
* All rights reserved.

* 作 者: 劉鎮
* 完成日期: 2012 年 11 月 10 日
* 版 本 號: 3.017

* 對任務及求解方法的描述部分

* 問題描述:窗體上有2個按鈕,一個顯示文本,一個顯示圖片。單擊上面按鈕,或按下alt+B可以彈出右邊所示的消息框。單擊下面按鈕也可以彈出右邊所示的消息框

 

*代碼部分:

 

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("單擊了我!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
            {
                Application.Exit();
            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            MyMessageBox();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MyMessageBox();
        }

        private void MyMessageBox()
        {
            if (DialogResult.Yes == MessageBox.Show("單擊了我!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2))
            {
                Application.Exit();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


 

 

測試結果:

 

 

心得經驗:

 

 

一、兩個按鈕都是Button只不過一個是沒有插入圖片,一個則設置了外觀中的Image;

二、怎樣實現固定Frame:FormBorderStyle設爲FixedSingle;

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章