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

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

其核心方法在 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. 方法不会等待Task执行完才返回数据

  2. Java回调机制在RPC框架中的应用示例

    完整源码: https://gitee.com/shiyanjun/x-callback-demo 应用场景描述: 服务提供者在项目启动时,创建并启动一个TCP服务器,然后将自己提供的所有服务注册到注 ...

  3. Python3基础 函数 参数 在设定缺省值的情况下指明参数类型

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  4. Python3基础 str ljust-rjust-center 左、右对齐 居中

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  5. SOD 框架

    http://www.pwmis.com/sqlmap/#yyal “老坛泡新菜”-SOD MVVM框架,让WinForms焕发新春 https://blog.csdn.net/ccc82284/ar ...

  6. Spring cloud微服务安全实战-5-5实现授权码认证流程(1)

    目前为止已经完成了完整的用户逻辑 目前的问题是,用户在登陆的时候,用户名提交的是给前端服务器的.每个前端服务器的开发人员都可能接触到前端的用户名密码. 每一个客户端应用都要去处理登陆的逻辑,一单我的登 ...

  7. 中标麒麟QT5编译出现:cannot find -lGL 和 collect2:error:ld returned 1 exit status 错误

    sudo yum install mesa-libGL-devel mesa-libGLU-devel

  8. 报错:Configured broker.id 68 doesn't match stored broker.id 113 in meta.properties

    报错背景: CDH中安装完成kafka的组件后不能成功启动,发现UI界面中的broker.id和服务器中的broker.id不一致, 因此更改了服务器中broker.id 但是更改完成之后还是报错. ...

  9. SQL Server 2014 清除用户名和密码

    网上找来找去都是SQL Server 2008版本或者以前版本的... 后来:http://stackoverflow.com/questions/349668/removing-the-rememb ...

  10. [ kvm ] 学习笔记 5:QEMU-KVM 命令详解

    1. QEMU.KVM .QEMU-KVM QEMU 提供了一系列的硬件模拟设备(cpu.网卡.磁盘等),客户机指令都需要QEMU翻译,因此性能较差.KVM 是Linux 内核提供的虚拟化模块,负责C ...