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

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

其核心方法在 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. MySQL 5.6&5.7 性能优化 TOP10(转)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/NLOneDay/article/deta ...

  2. 使用 ASP.NET Core 创建 Web API及链接sqlserver数据库

    创建 Web API https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.0& ...

  3. Linux_CentOS软件安装yum

    在 Linux 操作系统下,几乎所有的软件均通过 RPM 进行安装.卸载及管理等操作.RPM 的 全称为 Redhat Package Manager ,是由 Redhat 公司提出的,用于管理 Li ...

  4. 深入学习c++--容器

    1. 简介 1. 序列式容器: array, vector, deque, list, forward_list --- 数组 或者 指针实现 2. 关联容器: set, map, multiset, ...

  5. 零基础学Python-第一章 :Python介绍和安装-03.Python的安装

    官方版本的python下载以及安装方法,以及pycharm的安装和打开. 社区版就可以完全支持我们的需求了. 点击左侧的图片到右边. 在命令行输入python3 exit() 退出命令行的编辑器. p ...

  6. 一个兼容 node 与浏览器的模块写法

    一个兼容 node 与浏览器的模块写法 // test.js (function (root, factory) { if (typeof define === 'function' &&am ...

  7. Difference between Process and thread?

    What are the differences between a process and a thread? How are they similar? How can 2 threads com ...

  8. Java基础教程:多线程杂谈——双重检查锁与Volatile

    Java基础教程:多线程杂谈——双重检查锁与Volatile 双重检查锁 有时候可能需要推迟一些高开销的对象初始化操作,并且只有在使用这些对象时才进行初始化.此时程序员可能会采用延迟初始化.但要正确实 ...

  9. AWS 身份及验证服务(四)

    IAM 概述 集中管理访问AWS资源的访问权限和用户身份认证 支持联合访问管理,支持LADP第三方服务 (Identity Provider) 是非区域相关的服务,全局有效 创建用户.组和角色以应用策 ...

  10. 一段话让你理解vuex的工作模式!

    vuex 个人理解:管理各组件公共状态的vue插件,也是个组件相互通信的插件. 组成:1.State:状态树. 2.Getters:操作state. 3.Mutation:唯一改变state状态的操作 ...