C# WinForm MessageBox弹窗倒计时的自动关闭
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int SetWindowText(IntPtr hWnd, string text);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
/// <summary>
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
const int WM_CLOSE = 0x10;
const int BM_CLICK = 0xF5;
int FunCord;
IntPtr hwnd;
int t;
private void button1_Click(object sender, EventArgs e)
{
FunCord = 1;
t = 5;
timer1.Enabled = true;
MessageBox.Show("系统关机提示:\n\n 确认关机请点击【确定】\n\n 继续使用请点击【取消】", "系统将于" + t + "秒后关机", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
MessageBox.Show("直接关闭");
}
private void timer1_Tick(object sender, EventArgs e)
{
if (FunCord == 1)
{
hwnd = FindWindow(null, "系统将于" + t.ToString() + "秒后关机");
t = t - 1;
SetWindowText(hwnd, "系统将于" + t.ToString() + "秒后关机");
if (t == 0)
{
timer1.Enabled = false;
SendMessage(hwnd, WM_CLOSE, 0, 0);
}
}
else if (FunCord == 2)
{
hwnd = FindWindow(null, "关机提示");
IntPtr a = FindWindowEx(hwnd, (IntPtr)null, null, "系统将于" + t.ToString() + "秒后关机");
t = t - 1;
SetWindowText(a, "系统将于" + t.ToString() + "秒后关机");
if (t == 0)
{
timer1.Enabled = false;
SendMessage(hwnd, WM_CLOSE, 0, 0);
}
}
else if (FunCord == 3)
{
hwnd = FindWindow(null, "系统将于" + t.ToString() + "秒后关机");
t = t - 1;
SetWindowText(hwnd, "系统将于" + t.ToString() + "秒后关机");
if (t == 0)
{
IntPtr OKHwnd = FindWindowEx(hwnd, IntPtr.Zero, null, "确定");
SendMessage(OKHwnd, BM_CLICK, 0, 0);
timer1.Enabled = false;
}
}
else if (FunCord == 4)
{
hwnd = FindWindow(null, "系统将于" + t.ToString() + "秒后关机");
t = t - 1;
SetWindowText(hwnd, "系统将于" + t.ToString() + "秒后关机");
if (t == 0)
{
IntPtr OKHwnd = FindWindowEx(hwnd, IntPtr.Zero, null, "取消");
SendMessage(OKHwnd, BM_CLICK, 0, 0);
timer1.Enabled = false;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
FunCord = 2;
t = 5;
timer1.Enabled = true;
MessageBox.Show("系统将于" + t + "秒后关机", "关机提示");
timer1.Enabled = false;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
FunCord = 3;
t = 5;
timer1.Enabled = true;
if (MessageBox.Show("系统关机提示:\n\n 确认关机请点击【确定】\n\n 继续使用请点击【取消】", "系统将于" + t + "秒后关机", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.OK)
{
MessageBox.Show("点击了确定");
}
timer1.Enabled = false;
}
private void button4_Click(object sender, EventArgs e)
{
FunCord = 4;
t = 5;
timer1.Enabled = true;
if (MessageBox.Show("系统关机提示:\n\n 确认关机请点击【确定】\n\n 继续使用请点击【取消】", "系统将于" + t + "秒后关机", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
{
MessageBox.Show("点击了取消");
}
timer1.Enabled = false;
}
原文链接:https://www.itsvse.com/thread-4806-1-4.html
C# WinForm MessageBox弹窗倒计时的自动关闭的更多相关文章
- 对类HelloWorld程序中添加一个MessageBox弹窗
对类HelloWorld程序中添加一个MessageBox弹窗 分析: 任一程序运行的时候都会加载kernel32.dll的,但MessageBoxA()这个API却是在user32.dll中的.所以 ...
- 【C#】使用user32.dll的MessageBox弹窗消息
要使用user32.dll的MessageBox弹窗消息,自然需要引入user32.dll到项目中. 一个最简单的实例如下: using System; using System.Runtime.In ...
- layer.msg弹窗后没有自动关闭——问题解决
layer.msg弹窗后没有自动关闭,里面也没有配time: -1 layer.msg("信息体", {time: -1}); 后面发现是jquer和layer版本不对,之前自己用 ...
- winform messagebox自动关闭
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 玩转控件:重写/重绘Dev中MessageBox弹窗控件
很久没有更新博客了,本想着直接发一篇<手撕ERP>系列,从控件重写.重绘,到框架搭建,再到部分模块实现+业务的.但是每次动手的时候,都觉得难以下手.直接从数据库设计开始吧,模块设计还没定下 ...
- winform右下角弹窗
网页是否经常在电脑右下角弹窗显示消息?其实Winform也是可以实现的.下面介绍两种方法. 第一步:设计窗体 第二步:实现代码 第一种方法 引用user32 声明常量 窗体Load事件 窗体FormC ...
- C# WinForm MessageBox.Show显示在窗体中间
一.新建MessageBoxEx类,并添加以下代码. using System; using System.Windows.Forms; using System.Text; using System ...
- WinForm MessageBox 提示对话框
public class MessageUtil { /// <summary> /// 显示一般的提示信息 /// </summary> /// <param name ...
- C# Winform右下角弹窗方式
[方法一] 第一步:winform项目创建完成后,添加一个窗口,命名为:Messages .(加上最开始的Form1,一共为两个窗口),双击主窗口进入后台代码 . 第二步:在Messages 窗口中添 ...
随机推荐
- RabbitMQ direct交换器
1:队列和交换器多次绑定 String[] routekeys={"routekey1","routekey2","routekey3"}; ...
- Spring Boot 笔记 (8) - H2 数据库
Maven 依赖 <dependency> <groupId>com.h2database</groupId> <artifactId>h2</a ...
- 一:MySQL系列之基本介绍(一)
本篇主要介绍关于MySQL数据的基本知识,包括数据存储的变化,什么是MySQL以及其有什么优点.以及什么是RDBMS概念性知识等,以及关于MySQL语句的SOL的基本用法: 一.数据库 数据库,顾名思 ...
- java对象json序列化时忽略值为null的属性
环境: jdk: openjdk11 操作系统: windows 10教育版1903 目的: 如题,当一个对象里有些属性值为null 的不想参与json序列化时,可以添加如下注解 import com ...
- Replica set 的选举策略之一 (转)
首先介绍一下在replica set里分为三种节点类型: 1 primary 负责client的读写. 2 secondary 作为热备节点,应用Primary的oplog读取的操作日志,和pri ...
- Android手机测试环境搭建
Android SDK概念: SDK(software development kit)软件开发工具包.被软件开发工程师用于为特定的软件包.软件框架.硬件平台.操作系统等建立应用软件的开发工具的集合. ...
- typescript 接口
接口:用来建立某种代码约定,使得其他开发者在调用某个方法或创建新的类时必须遵循接口所定义的代码约定 在js里面没有接口这个概念,在ts里面通过两个关键字来支撑接口这个特性 interface ...
- 一道简单的广搜题:Knight Moves
这本来是要用双向宽度搜索的,但是我用简单的广搜也成功了,L<=300,也不会超时?? 另外一个问题就是,我本来想用原来的代码交,结果80分??将边界条件从小于L改成小于等于L,就对了.我可能不会 ...
- 《S》读后感
利用周末时间读完了<S>,有一幅画面在脑袋里挥之不去:一条急湍直下的河,岸边茂密的枝叶延伸到河面上,很多人被河水冲向前方,每个人的眼里都夹杂着凄凉与愤怒,时不时回头,,想同这河水做一次歇斯 ...
- NOIP 2017 PJ
T1:水 T2:水 T3:水 T4:水,二分+DP检测+单调队列优化,然而优化写炸了,还没暴力分高 所以爆炸 (民间)100 + 100 + 100 + 10 = 310 GAME OVER