C#(winform)项目中自制alert提示窗体

本文介绍如何在C#应用程序中为自定义窗体添加系统图标资源。通过重写绘图事件并利用SystemIcons类,可以轻松实现这一功能。

先来个图片:

2009121512393742.jpg

再上代码

ContractedBlock.gifExpandedBlockStart.gif代码
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gtusing 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
{
///
/// 构造函数
///
public CloseForm()
{
InitializeComponent();
this.DialogResult = DialogResult.Cancel;
}
///
/// 确定按钮点击事件
///
///
///
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
this.DialogResult = DialogResult.OK;
}
else
{
this.DialogResult = DialogResult.No;
}
this.Close();
}
///
/// 绘图事件
///
///
protected override void OnPaint(PaintEventArgs e)
{
Graphics g
= e.Graphics;
Icon icon
= SystemIcons.Question;
g.DrawIcon(icon,
30, 16);
}
///
/// 取消按钮点击事件
///
///
///
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}

}
}

其中绘图事件的代码比较重要

全靠这两句代码让这个窗体有了系统icon资源

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12639172/viewspace-622489/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12639172/viewspace-622489/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值