首页 > Windows开发 > 详细

C#长按事件

时间:2018-10-23 10:36:52      阅读:357      评论:0      收藏:0      [点我收藏+]

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;
namespace WpfApplication9
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
bool isPressed;
bool entryTouch;
Thread th = null;
public delegate void CloseDelegate();
CloseDelegate closeDelegate;

public MainWindow()
{
InitializeComponent();
isPressed = false;
entryTouch = false;
}
private void Btn_MouseDown(object sender, RoutedEventArgs e)
{
isPressed = true;
if (th != null)
{
if (th.ThreadState == ThreadState.Running || th.ThreadState == ThreadState.WaitSleepJoin)
{
th.Abort();
}
}
th = new Thread(new ThreadStart(()=>{
Thread.Sleep(1500);
if (isPressed)
{
MessageBox.Show("长按1.5秒");
isPressed = false;
}
else
{
MessageBox.Show("少于1.5秒");
}
}));
th.Start();

}
private void Btn_MouseUp(object sender, RoutedEventArgs e)
{
if (entryTouch)
{
MessageBox.Show("进入长按事件");
}
isPressed = false;
}
}
}

C#长按事件

原文:https://www.cnblogs.com/sundh1981/p/9834700.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!