前两天实现某个功能需要做一个提示框 并且能够自动关闭的,就从网上搜了一个能够自动关闭的提示框 ,但由于我需要的场景是不确定计时时间的,所以并没有使用到该窗体,但是我觉得可以留存备用 ,后边也把我

这种倒计时的提示框用处还是很多的,用于自动弹窗 自动关闭 ,虽然在我的项目中没有

其核心方法在 timer(TimerCallBack,Object,int32,int32) TimerCallBack 是一个委托 ,代表要执行的方法,其用途可以用在各个定时去调用方法的场景,而且可以设置窗体的FormBorderStyle的属性为None,设置窗体边框和标题栏外观不显示.

以下为网上找的一段代码实现的定时关闭窗体的功能  ,但由于是之前找的,已经找不到原作者,在此表示十分抱歉

以下代码非本人编写:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace Demo
{
public partial class AutoCloseMessageBox : Form
{
public AutoCloseMessageBox()
{
InitializeComponent();
}
public void getMassage(string text)
{
label1.Text = text;
} public void GetText(string caption)
{
this.Text = caption;
} System.Threading.Timer _timeoutTimer;
string _caption; AutoCloseMessageBox(string text, string caption, int timeout)
{
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite); AutoCloseMessageBox m_MassageBox = new AutoCloseMessageBox();
m_MassageBox.getMassage(text);
m_MassageBox.GetText(caption);
m_MassageBox.ShowDialog(); public static void Show(string text, string caption, int timeout)
{
new AutoCloseMessageBox(text, caption, timeout);
} void OnTimerElapsed(object state)
{
IntPtr mbWnd = FindWindow(null, _caption);
if (mbWnd != IntPtr.Zero)
SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
_timeoutTimer.Dispose();
}
const int WM_CLOSE = 0x0010;
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); }
}

调用时直接使用类名.show(text,captiom,timeout) 直接调用即可

下边是当时的项目使用场景的解决办法

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace NewuView.Mix
{
public partial class ErrorForm : Form
{
public ErrorForm()
{
InitializeComponent();
} private void BarcodeErrorForm_Load(object sender, EventArgs e)
{
this.ShowInTaskbar = false;
} public void Clear()
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(Clear));
}
else
{
this.richTextBox1.Clear();
}
} public void SetMsg(string msg)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new Action<string>(SetMsg), msg);
}
else
{
this.richTextBox1.AppendText(msg + Environment.NewLine);
}
} public Point Point1 { get; set; }
public void ShowForm()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(ShowForm));
}
else
{
this.Location = Point1;
this.BringToFront();
this.Visible = true;
}
} public void HideForm()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(HideForm));
}
else
{
this.richTextBox1.Clear();
this.Visible = false;
}
} }
}

该窗体可以用于实时监控某一个状态时 而弹出的提示框 并根据状态改变而隐藏

使用时,new一个该errorForm

在该窗体有一个RichTextBox,用来显示提示信息,使用SetMsg,设置要显示的信息

需要弹出时,实例调用Show()方法  实际就是讲该窗体的visible属性置为true,让窗体显示,并且调用Clear方法,清除提示信息

需要隐藏时,实例调用HideForm()方法,将窗体visible属性设置为false,调用clear方法,清除提示信息

C#倒计时关闭提示框的更多相关文章

  1. 基于Metronic的Bootstrap开发框架经验总结(6)--对话框及提示框的处理和优化

    在各种Web开发过程中,对话框和提示框的处理是很常见的一种界面处理技术,用得好,可以给用户很好的页面体验,Bootstrap开发也一样,我们往往在页面新增.编辑.查看详细等界面使用弹出对话框层的方式进 ...

  2. IOS 加载中提示框

    LoadingView.h #import <Foundation/Foundation.h> @class MBProgressHUD; @interface LoadingView : ...

  3. [转]Angular——提示框

    本文转自:https://blog.csdn.net/whm18322394724/article/details/80177950 版权声明:本文为博主原创文章,未经博主允许不得转载. https: ...

  4. Appium之打开应用时提示框处理

    当打开一个应用时,会有一个无关紧要的提示框,如果要继续操作,需要先关闭提示框,如下图(如新用户福利提示): 此时,如果你直接用Appium inspector或者Android uiautomator ...

  5. (转)基于Metronic的Bootstrap开发框架经验总结(6)--对话框及提示框的处理和优化

    http://www.cnblogs.com/wuhuacong/p/4775282.html 在各种Web开发过程中,对话框和提示框的处理是很常见的一种界面处理技术,用得好,可以给用户很好的页面体验 ...

  6. wpf实现仿qq消息提示框

    原文:wpf实现仿qq消息提示框 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details/5052 ...

  7. 微信小程序API交互反馈,wx.showToast显示消息提示框

    导读:wx.showToast(OBJECT) 显示消息提示框. OBJECT参数说明: 参数 类型 必填 说明 最低版本 title String 是 提示的内容 icon String 否 图标, ...

  8. uni-app开发经验分享六:页面跳转及提示框

    在我们开发的uni-app的过程中,页面跳转及提示框往往是我们做数据交互及结果反馈所要使用的功能,这里分享下我收集的一些方法及看法. 一:页面跳转 事件跳转 :指通过tap等事件来实现页面的跳转,跳转 ...

  9. Win7关机出现关闭程序提示框

    运行输入Gpedit.msc回车打开组策略,在左侧选计算机配置/管理模板/系统/关机选项,在右侧双击“关闭会阻止或取消关机的应用程序的自动终止功能”,在打开的提示框中选“已启用”,按确定即可.

随机推荐

  1. centos7.6_x86_64使用Squid搭建代理服务器让windows上网

    centos7.6_x86_64使用Squid搭建代理服务器让windows上网 windows机器很多站点访问受限,可以在没有限制外网的机器上面搭建代理服务器,其它电脑可以配置代理通过这台不受限制的 ...

  2. idea-debug启动会卡住不动,BeanPostProcessors (for example: not eligible for auto-proxying),报错解决

    debug启动会卡住不动,run模式启动正常 debug启动输出到下面这行之后,就不会继续输出了 爆出各种 [INFO]- Bean 'dataSource' of type [class Druid ...

  3. VS2015 dlib编译 x64 Debug .lib生成

    VS2015 dlib编译 x64 Debug >------ 已启动生成: 项目: ZERO_CHECK, 配置: Debug x64 ------ > Checking Build S ...

  4. error C2061: 语法错误: 标识符“openmode”

    今天在一台新机子上编译项目,出现了这个错误,不知如何解决,先记录一下. 1>------ 已启动全部重新生成: 项目: ZERO_CHECK, 配置: Debug x64 ------1> ...

  5. ES6深入浅出-13 Proxy 与 Reflect-1.Reflect 反射

    阮一峰  http://es6.ruanyifeng.com/#docs/reflect MDN有一些简陋的介绍 https://developer.mozilla.org/zh-CN/docs/We ...

  6. Qt编写自定义控件65-光晕日历

    一.前言 操作系统的更新迭代速度非常快,基本上三五年就有个新版本出来,WIN10操作系统还是一个比较成功的系统,据说现在市场份额越来越大,XP的份额已经很小,WIN7的份额也在逐步减少,在最新的WIN ...

  7. **209. Minimum Size Subarray Sum 长度最小的子数组

    1. 题目描述 给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的连续子数组.如果不存在符合条件的连续子数组,返回 0. 示例: 输入: s = 7, nu ...

  8. SpringBoot中日志配置

    背景 由于一些框架中还使用log4j-1.x系列陈旧的日志框架,调试过程中有一些错误信息不能在控制台显示,增加了调试成本.以下配置方法 将帮助你获得log4j-1.x日志在控制台显示. 解决方法: 使 ...

  9. sublime text 3 前端开发常用插件

    sublime text 3 前端开发常用插件 https://packagecontrol.io/browse 代码对齐: Alignment html代码补全:  Emmet CoffeeScri ...

  10. 09点睛Spring MVC4.1-异步请求处理(包含兼容浏览器的服务器端推送)

    转发地址:https://www.iteye.com/blog/wiselyman-2215852 9.1 异步请求处理 Servlet 3开始支持异步请求处理 Spring MVC 3.2开始支持S ...