先来个图片:
再上代码
代码
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;
using System.Reflection;
namespace FB.FormHelper
{
public partial class CloseForm : Form
{
/// <summary>
/// 构造函数
/// </summary>
public CloseForm()
{
InitializeComponent();
this .DialogResult = DialogResult.Cancel;
}
/// <summary>
/// 确定按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click( object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this .DialogResult = DialogResult.OK;
}
else
{
this .DialogResult = DialogResult.No;
}
this .Close();
}
/// <summary>
/// 绘图事件
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Icon icon = SystemIcons.Question;
g.DrawIcon(icon, 30 , 16 );
}
/// <summary>
/// 取消按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click( object sender, EventArgs e)
{
this .Close();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace FB.FormHelper
{
public partial class CloseForm : Form
{
/// <summary>
/// 构造函数
/// </summary>
public CloseForm()
{
InitializeComponent();
this .DialogResult = DialogResult.Cancel;
}
/// <summary>
/// 确定按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click( object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this .DialogResult = DialogResult.OK;
}
else
{
this .DialogResult = DialogResult.No;
}
this .Close();
}
/// <summary>
/// 绘图事件
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Icon icon = SystemIcons.Question;
g.DrawIcon(icon, 30 , 16 );
}
/// <summary>
/// 取消按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click( object sender, EventArgs e)
{
this .Close();
}
}
}
其中绘图事件的代码比较重要
全靠这两句代码让这个窗体有了系统icon资源