在WinForm中单击窗体右上角关闭按钮后,如何延迟一秒钟后再关闭窗体? 在窗体关闭事件里写就可以了,加个timer不就得了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Closing里处理就行了,如加个退出的参数标志,看标志是否翻转了 可Closing不会停下来啊,继续下行执行,结果窗体就关闭了:(高手们能不能写两行代码啊?呵呵~~ using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace WindowsApplication10{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components; private int TimeControl=0; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); // // timer1 // this.timer1.Interval = 1000; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 273); this.Name = "Form1"; this.Text = "Form1"; this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Closing(object sender, CancelEventArgs e) { this.timer1.Start(); if (this.TimeControl==0) { e.Cancel=true; } else { e.Cancel=false; } } private void timer1_Tick(object sender, System.EventArgs e) { this.TimeControl++; this.Dispose(); } }} 如何调出任务管理器 大家帮我分析个错误原因,高分酬谢 救命,急急争,快点帮帮我,一个关于GridView的问题!~ 异步本来就是多线程,可以支持多个用户同时连接,用异步写服务器还用在thread线程吗? 请问WinForm如何上传文件 怎样将24位,32位,8位的bmp文件压缩或转换成16位的bmp文件。以及怎样从bmp文件中读取出原始数据?在线等! 关于收发短信息的C#实现 谁能推荐学习的C# WEB开发的资料? 有谁知道分页读取数据? 一个很菜的问题:按钮无法加入到窗体? 哪儿有开源项目SharpDevelop的源代码? 高手请回答,急!
高手们能不能写两行代码啊?
呵呵~~
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication10
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private int TimeControl=0;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Closing(object sender, CancelEventArgs e)
{
this.timer1.Start();
if (this.TimeControl==0)
{
e.Cancel=true;
}
else
{
e.Cancel=false;
}
} private void timer1_Tick(object sender, System.EventArgs e)
{
this.TimeControl++;
this.Dispose();
}
}
}