按下c#时检测多点触摸
本文关键字:多点 触摸 检测 按下 | 更新日期: 2023-09-27 18:23:42
我想检测触摸事件,并在手指向下触摸时做一些事情。
我需要什么活动?
我试过操纵*、指针*、触摸*、触控笔*、握持*等…
如果你有一个示例代码,那就更好了。
我拥有的最准确的代码是这个。但只适用于手指移动。
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Rectangle Name="Rect1" IsManipulationEnabled="True" Fill="Blue" HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" Margin="108,50,309,169" ManipulationDelta="Rect1_ManipulationDelta" />
<Rectangle Name="Rect2" IsManipulationEnabled="True" Fill="Blue" HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" Margin="338,50,79,169" ManipulationDelta="Rect2_ManipulationDelta" />
<TextBox Name="Text1" Text="0" HorizontalAlignment="Left" Height="23" Margin="108,267,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="100"/>
<TextBox Name="Text2" Text="0" HorizontalAlignment="Left" Height="23" Margin="338,267,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="100"/>
</Grid>
namespace WpfApplication2
{
public partial class MainWindow : System.Windows.Window
{
System.Windows.Input.ManipulationModes currentMode = System.Windows.Input.ManipulationModes.All;
public MainWindow()
{
InitializeComponent();
}
private void Rect1_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
int variable = 0;
variable = Convert.ToInt32(Text1.Text);
variable++;
Text1.Text = variable.ToString();
}
private void Rect1_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
int variable = 0;
variable = Convert.ToInt32(Text1.Text);
variable++;
Text1.Text = variable.ToString();
}
private void Rect2_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
{
int variable = 0;
variable = Convert.ToInt32(Text2.Text);
variable++;
Text2.Text = variable.ToString();
}
private void Rect2_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
int variable = 0;
variable = Convert.ToInt32(Text2.Text);
variable++;
Text2.Text = variable.ToString();
}
}
}
Touch*事件只会给你触摸。指针*将为您提供触摸、鼠标和手写笔。
使用*向下可以知道触摸何时下降,使用*向上可以知道触摸什么时候上升。如果您想在按下触摸时重复执行某些操作,请在*down上创建一个DispatcherTimer,并在*Up 上停止它
UIElement/ContentElement.TouchDown是您需要完成的事件。
示例:
<Rectangle Name="Rect1" IsManipulationEnabled="True" Fill="Blue" HorizontalAlignment="Center" Height="100" VerticalAlignment="Center" Width="100" Margin="108,50,309,169" TouchDown="Rect1_TouchDown" />
private void Rect1_TouchDown(object sender, TouchEventArgs e)
{
// Do stuff
}
有关更多信息,请参阅:http://msdn.microsoft.com/en-us/library/system.windows.uielement.touchdown(v=vs.110).aspx和http://msdn.microsoft.com/en-us/library/ms754010(v=vs.110).aspx