如何在Slider中使用MouseLeftButtonDown事件
1个回答
展开全部
private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var element = (FrameworkElement)sender;
if (e.ClickCount == 1)
{
var timer = new System.Timers.Timer(500);
timer.AutoReset = false;
timer.Elapsed += new ElapsedEventHandler((o, ex) => element.Dispatcher.Invoke(new Action(() =>
{
var timer2 = (System.Timers.Timer)element.Tag;
timer2.Stop();
timer2.Dispose();
UIElement_Click(element, e);
})));
timer.Start();
element.Tag = timer;
}
if (e.ClickCount > 1)
{
var timer = element.Tag as System.Timers.Timer;
if (timer != null)
{
timer.Stop();
timer.Dispose();
UIElement_DoubleClick(sender, e);
}
}
}
private void UIElement_Click(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("单击");
}
private void UIElement_DoubleClick(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("双击");
}
{
var element = (FrameworkElement)sender;
if (e.ClickCount == 1)
{
var timer = new System.Timers.Timer(500);
timer.AutoReset = false;
timer.Elapsed += new ElapsedEventHandler((o, ex) => element.Dispatcher.Invoke(new Action(() =>
{
var timer2 = (System.Timers.Timer)element.Tag;
timer2.Stop();
timer2.Dispose();
UIElement_Click(element, e);
})));
timer.Start();
element.Tag = timer;
}
if (e.ClickCount > 1)
{
var timer = element.Tag as System.Timers.Timer;
if (timer != null)
{
timer.Stop();
timer.Dispose();
UIElement_DoubleClick(sender, e);
}
}
}
private void UIElement_Click(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("单击");
}
private void UIElement_DoubleClick(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("双击");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询