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