silverlight鼠标双击2
2009-02-11 16:43
134 查看
网友做的一个双击的例子
原理是
第一次点击 开一个线程(sheep 200 且 lock)
如果在200ms内再点击 线程继续sheep 200 统计点击次数
...........
............
timeout 后
线程执行 比较传入的要求点击数与统计点击的次数
true 的话就执行
public class MClick
{
public static void MulClick(int count, MouseButtonEventHandler handle, object sender, MouseButtonEventArgs e)
{
bolClicking = true;
if (bolClicked)
{
intClickCount++;
}
else
{
bolClicked = true;
intCount = count;
handleClick = handle;
objSender = sender;
mbeE = e;
asyncOperation = AsyncOperationManager.CreateOperation(null);
objThreadLock = new object();
Thread thread = new Thread(ResetThread);
thread.Start();
while (!thread.IsAlive) ;
}
}
private static int intTimeOut = 200;
public static int TimeOut
{
get
{
return intTimeOut;
}
set
{
intTimeOut = value < 1 ? 1 : value;
}
}
private static int intCount;
private static object objSender;
private static MouseButtonEventArgs mbeE;
private static MouseButtonEventHandler handleClick;
private static int intClickCount = 0;
private static bool bolClicked = false;
private static bool bolClicking = false;
private static object objThreadLock;
private static AsyncOperation asyncOperation;
private static void ResetThread()
{
while (bolClicking)
{
bolClicking = false;
Thread.Sleep(TimeOut);
}
lock(objThreadLock)
{
if (intCount == ++intClickCount)
{
asyncOperation.Post(callback, objSender);
}
intClickCount = 0;
bolClicked = false;
}
}
private static void callback(object state)
{
handleClick(objSender, mbeE);
}
}
============================
只是测试性,满乱的~~哈哈。有兴趣的朋友可以改进~
改成
MulClick(点击次数, 控件, 函数)
使用
==============================
public Page()
{
InitializeComponent();
LayoutRoot.MouseLeftButtonUp += new MouseButtonEventHandler(HandleClick);
}
private void HandleClick(object sender, MouseButtonEventArgs e)
{
//MClick.MulClick(1, onClick, sender, e);
MClick.MulClick(2, onDoubleClick, sender, e);
}
private void onClick(object sender, MouseButtonEventArgs e)
{
txtMsg.Text = "单击";
}
private void onDoubleClick(object sender, MouseButtonEventArgs e)
{
txtMsg.Text = "双击";
}
}
原理是
第一次点击 开一个线程(sheep 200 且 lock)
如果在200ms内再点击 线程继续sheep 200 统计点击次数
...........
............
timeout 后
线程执行 比较传入的要求点击数与统计点击的次数
true 的话就执行
public class MClick
{
public static void MulClick(int count, MouseButtonEventHandler handle, object sender, MouseButtonEventArgs e)
{
bolClicking = true;
if (bolClicked)
{
intClickCount++;
}
else
{
bolClicked = true;
intCount = count;
handleClick = handle;
objSender = sender;
mbeE = e;
asyncOperation = AsyncOperationManager.CreateOperation(null);
objThreadLock = new object();
Thread thread = new Thread(ResetThread);
thread.Start();
while (!thread.IsAlive) ;
}
}
private static int intTimeOut = 200;
public static int TimeOut
{
get
{
return intTimeOut;
}
set
{
intTimeOut = value < 1 ? 1 : value;
}
}
private static int intCount;
private static object objSender;
private static MouseButtonEventArgs mbeE;
private static MouseButtonEventHandler handleClick;
private static int intClickCount = 0;
private static bool bolClicked = false;
private static bool bolClicking = false;
private static object objThreadLock;
private static AsyncOperation asyncOperation;
private static void ResetThread()
{
while (bolClicking)
{
bolClicking = false;
Thread.Sleep(TimeOut);
}
lock(objThreadLock)
{
if (intCount == ++intClickCount)
{
asyncOperation.Post(callback, objSender);
}
intClickCount = 0;
bolClicked = false;
}
}
private static void callback(object state)
{
handleClick(objSender, mbeE);
}
}
============================
只是测试性,满乱的~~哈哈。有兴趣的朋友可以改进~
改成
MulClick(点击次数, 控件, 函数)
使用
==============================
public Page()
{
InitializeComponent();
LayoutRoot.MouseLeftButtonUp += new MouseButtonEventHandler(HandleClick);
}
private void HandleClick(object sender, MouseButtonEventArgs e)
{
//MClick.MulClick(1, onClick, sender, e);
MClick.MulClick(2, onDoubleClick, sender, e);
}
private void onClick(object sender, MouseButtonEventArgs e)
{
txtMsg.Text = "单击";
}
private void onDoubleClick(object sender, MouseButtonEventArgs e)
{
txtMsg.Text = "双击";
}
}
相关文章推荐
- 稳扎稳打Silverlight(32) - 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件
- Silverlight实用窍门系列:11.Silverlight中为自定义控件添加鼠标双击属性,Silverlight模拟鼠标双击【附带源码实例】
- silverlight 自定义 鼠标 双击事件
- Silverlight 鼠标双击事件处理
- 11.Silverlight中为自定义控件添加鼠标双击属性,Silverlight模拟鼠标双击
- Silverlight 4以下版本模拟鼠标双击事件
- silverlight鼠标双击
- Silverlight模拟鼠标双击事件
- MVVM Silverlight 5 Datagrid MVVM 鼠标双击事件
- Silverlight - 鼠标右键及左键双击事件
- 稳扎稳打Silverlight(32) - 2.0Tip/Trick之MessageBox, Popup, 循环的几种实现方法, 动态变换主题, 本地化(多语言), 响应鼠标双击事件
- Silverlight 5 beta新特性探索系列:4.Silverlight 5 beta中鼠标双击/鼠标多重点击的实现
- silverlight鼠标双击1
- Silverlight 5 beta新特性探索系列:4.Silverlight 5 beta中鼠标双击/鼠标多重点击的实现
- Silverlight DataGrid鼠标双击事件
- Silverlight实用窍门系列:12.继承于某些固定控件(以Grid为例)的鼠标左键双击事件的实现【附带实例源码】
- Silverlight 鼠标双击 事件
- silverlight 自定义 鼠标 双击事件
- Silverlight中创建自己的Behavior(为Silverlight添加鼠标双击和滚轮支持)
- 当鼠标左键双击弹出多个时