zoukankan      html  css  js  c++  java
  • C# WinForm 提示框延迟自动关闭

    有时候我们需要弹出个提示框然后让它自己关闭,然而实际使用中的弹出框确实阻塞进程,网上貌似有一种另类的解决方式,大致思路是把弹出框放到另外的一个窗体上,直接贴代码

    主窗体

    using System;
    using System.Windows.Forms;
    
    namespace WinForm
    {
        public partial class MainForm : Form
        {
            public MainForm()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //延迟800毫秒关闭的信息框
                MessageBox.Show(new DelayCloseForm(800), "执行成功!");
            }
        }
    }
    

      

    起到延迟作用的窗体

    using System;
    using System.ComponentModel;
    using System.Windows.Forms;
    
    namespace WinForm
    {
        public partial class DelayCloseForm : Form
        {
            public DelayCloseForm(int interval = 500)
            {
                InitializeComponent();
                //计时器
                this.components = new Container();
                Timer timer1 = new Timer(this.components);
                timer1.Enabled = true;
                timer1.Interval = interval;
                timer1.Tick += timer1_Tick;
                timer1.Start();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                this.Close();
            }
        }
    }
    

      

  • 相关阅读:
    bootloader
    Arm中的c和汇编混合编程
    Linux学习笔记(一)
    java按所需格式获取当前时间
    java 串口通信 rxtx的使用
    Tomcat数据库连接池
    面试
    复习 模拟call apply
    复习 js闭包
    复习js中的原型及原型链
  • 原文地址:https://www.cnblogs.com/luludongxu/p/8856956.html
Copyright © 2011-2022 走看看