* 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;