一站式网站建设服务商,城市生活服务app下载,南山做网站教程,客厅设计刚学C#不久#xff0c;就写个工具#xff0c;总结写一个简便自定义提示窗口方法#xff0c;并自动关闭。
1.在项目添加windows form#xff08;非user control#xff09;#xff0c;命名为Form_wait。 2.在Form_wait,加入需要控件与一个定时器timer1。
数字10为计时显…刚学C#不久就写个工具总结写一个简便自定义提示窗口方法并自动关闭。
1.在项目添加windows form非user control命名为Form_wait。 2.在Form_wait,加入需要控件与一个定时器timer1。
数字10为计时显示10秒后自动默认选择“是”
timer1 属性interval 设为1000即 tick事件1s进入 3.定义Form_wait响应事件 private void timer1_Tick(object sender, EventArgs e) //1s进入一次{count - 1;this.label2.Text count.ToString();if(count0){this.timer1.Stop();this.DialogResult DialogResult.OK; //这里是重点在主窗口里能读取返回值 }}private void button1_Click(object sender, EventArgs e) //“是”{this.timer1.Stop();this.DialogResult DialogResult.OK;}private void button2_Click(object sender, EventArgs e){this.timer1.Stop();this.DialogResult DialogResult.No;}4.主窗口调用。 Form_wait subform new Form_wait(15); //15为设定倒时if (subform.ShowDialog() DialogResult.No){MessageBox.Show(跳出控件);return;}