WPF DispatcherTimer(定时器应用) 无人触摸60s自动关闭窗口
原文:WPF DispatcherTimer(定时器应用) 无人触摸60s自动关闭窗口
如果无人触摸:60s自动关闭窗口
xmal:部分
<s:SurfaceWindow x:Class="SurfaceApplication1.SurfaceWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.microsoft.com/surface/2008"
Title="SurfaceApplication1"
TouchDown="SurfaceWindow_TouchDown"
>
<Grid >
<Button Width="80" Height="80" Background="Yellow" Click="Button_Click">OK</Button>
<Label x:Name="lblSeconds"> 你好!</Label>
</Grid>
</s:SurfaceWindow>
cs:部分
//60s无人操作自动关闭
DispatcherTimer dTimer;
private void Button_Click(object sender, RoutedEventArgs e)
{
//构造一个DispatcherTimer类实例
dTimer = new System.Windows.Threading.DispatcherTimer();
//设置事件处理函数
dTimer.Tick += new EventHandler(dispatcherTimer_Tick);
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
this.Close();
}
//触摸后重新给“i”赋值
private void SurfaceWindow_TouchDown(object sender, TouchEventArgs e)
{
int i = 60;
//定时器时间间隔1s
if ( dTimer.Interval!=null)
{
dTimer.Interval = new TimeSpan(0, 0, i);
dTimer.Start();
}
}
WPF DispatcherTimer(定时器应用) 无人触摸60s自动关闭窗口的更多相关文章
- WPF 使用定时器
WPF 使用定时器:<ProgressBar Height="10" HorizontalAlignment="Left" Margin="28 ...
- WPF中定时器与进度条的配合使用
WPF中定时器使用的注意事项: WPF需要使用System.Windows.Threading.DispatcherTimer定时器,而不能使用System.Timers.Timer定时器.因为Sys ...
- 通过 AppSwitch 禁用 WPF 内置的触摸让 WPF 程序可以处理 Windows 触摸消息
原文:通过 AppSwitch 禁用 WPF 内置的触摸让 WPF 程序可以处理 Windows 触摸消息 WPF 框架自己实现了一套触摸机制,但同一窗口只能支持一套触摸机制,于是这会禁用系统的触摸消 ...
- JavaScript自动关闭窗口
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- WPF 判断一个对象是否是设计时的窗口类型,而不是运行时的窗口
原文:WPF 判断一个对象是否是设计时的窗口类型,而不是运行时的窗口 当我们对 Window 类型写一个附加属性的时候,在属性变更通知中我们需要判断依赖对象是否是一个窗口.但是,如果直接判断是否是 W ...
- WPF中定时器Timer与DispatcherTimer的用法
最近的工作项目中需要定时更新UI控件中的数据,这时候第一反应肯定会想到去使用System.Timers.Timer定时更新UI控件,但是程序运行后,会发现程序崩溃了.报的异常为“调用线程无法访问此对象 ...
- WPF的定时器
一.注意事项 引用命名空间:System.Windows.Threading.DispatcherTimer. 二.使用方法 var _timer = new DispatcherTimer(); _ ...
- WPF单线程定时器 简单实例
//窗体加载完毕 void MyMessageBox_Loaded(object sender, RoutedEventArgs e) { //启动定时期倒计时,多线程计时 //System.Thre ...
- WPF程序长时间无人操作
在软件开发中为了安全性,特别是那些需要用到用户名和密码登录服务端的程序,常常考虑长期无人操作,程序自动跳转到用户登录界面. 判断程序是否长时间无人操作,有两个依据,第一个是鼠标长时间不动,第二个是鼠标 ...
随机推荐
- URL validation failed. The error could have been caused through the use of the browser's navigation
URL validation failed. The error could have been caused through the use of the browser's navigation ...
- Havel-Hakimi定理 hdu2454 / poj1695 Havel-Hakimi定理
Havel-Hakimi定理 当年一度热门出如今ACM赛场上的算法. 算法定义: Havel-Hakimi定理主要用来判定一个给定的序列是否是可图的. 2.首先介绍一下度序列:若把图 G 全部顶点的度 ...
- javascript合并数组并且删除第二项
var m1 = [5, 6, 2]; var m2 = [4, 2, 6]; var m3 = new Array(); m1 = m1.concat(m2); for ( ...
- 什么是uuid以及uuid在java中的使用
什么是UUID?UUID是Universally Unique Identifier的缩写,它是在一定的范围内(从特定的名字空间到全球)唯一的机器生成的标识符.UUID具有以下涵义: 经由一定的算法机 ...
- Thermal management in a gaming machine
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to wager gaming ...
- [Android]使用化名(alias)功能防止相同资源的重复
在为一个应用匹配不同资源文件的时候,有时可能需要在不同适配类型的资源路径下使用相同的资源文件,这时使用alias方法可以防止相同资源文件的重复,提高效率.以下摘自Android开发文档http://d ...
- Druid 专题
数据源配置: #datasource #Introductions: https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7 ...
- Method and apparatus for encoding data to be self-describing by storing tag records describing said data terminated by a self-referential record
A computer-implemented method and apparatus in a computer system of processing data generated by a f ...
- Ubuntu不输入密码执行sudo命令方法介绍
作为ubuntu等桌面系统,默认登录的帐号是没有root权限的,为了提升权限来执行任务,我们一般用到sudo+命令来执行,但是不难发现我们一般都要输入密码.那么有没有什么方法可以让我们执行sudo的时 ...
- Optimizing concurrent accesses in a directory-based coherency protocol
In one embodiment, the present invention includes a directory to aid in maintaining control of a cac ...