C#长按事件


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;
}
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM