c# 窗口关闭提示

winform关闭窗口前提示一下

/// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_LoginOut_Click(object sender, EventArgs e)
        {
            
            if (MessageBox.Show("确定要退出程序", "退出",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                SystemContext.Clear();
                // 关闭
                Application.Exit();
            }
        }


C#中创建一个具有延时关闭功能的提示窗口,你可以使用`System.Windows.Forms.Timer`来实现计时器,当计时结束时关闭窗口。以下是一个简单的示例代码,展示如何创建一个带有延时关闭功能的提示窗口: ```csharp using System; using System.Windows.Forms; public class DelayedMessageBox : Form { private Timer timer; private int delayInSeconds; public DelayedMessageBox(string message, int delayInSeconds) { this.delayInSeconds = delayInSeconds; this.Text = "提示"; this.Size = new System.Drawing.Size(400, 200); this.StartPosition = FormStartPosition.CenterScreen; Label label = new Label(); label.Text = message; label.AutoSize = true; label.Location = new Point(15, 15); this.Controls.Add(label); this.timer = new Timer(); this.timer.Interval = delayInSeconds * 1000; // 将秒转换为毫秒 this.timer.Tick += new EventHandler(timer_Tick); this.timer.Start(); } private void timer_Tick(object sender, EventArgs e) { this.timer.Stop(); this.Close(); } [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); DelayedMessageBox mb = new DelayedMessageBox("这是一个延时关闭提示窗口", 5); // 延迟5秒关闭 Application.Run(mb); } } ``` 在这个示例中,`DelayedMessageBox`类继承自`Form`类,创建了一个带有消息的窗口,并设置了计时器。计时器的`Tick`事件在指定的延迟时间到达后触发,停止计时器并关闭窗口
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值