1. 程式人生 > >#748 – 獲得按下時對應位置點的大小(Getting the Size of a Contact Point during Raw Touch)

#748 – 獲得按下時對應位置點的大小(Getting the Size of a Contact Point during Raw Touch)

ini bounds event view hup main.c .cn hand phoenix

原文:#748 – 獲得按下時對應位置點的大小(Getting the Size of a Contact Point during Raw Touch)

原文地址:https://wpf.2000things.com/2013/02/04/748-getting-the-size-of-a-contact-point-during-raw-touch/

在低級別的觸屏Touch 事件中,我們可以獲得手指與屏幕接觸的位置的面積大小。獲得這個信息可以通過TouchPoint.Bounds?屬性(請註意,即使驅動層不支持,該屬性也有值,可能會有為0的大小)。

下面是一個例子,在觸摸的位置根據接觸的大小畫一個橢圓。

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        TouchEllipses = new Dictionary<int, Ellipse>();
    }
 
    private Dictionary<int, Ellipse> TouchEllipses;
 
    private void Canvas_TouchDown(object sender, TouchEventArgs e)
    {
        canvMain.CaptureTouch(e.TouchDevice);
        TouchPoint tp = e.GetTouchPoint(canvMain);
 
        Ellipse el = new Ellipse();
        el.Stroke = Brushes.Black;
        el.Fill = Brushes.Black;
 
        el.Width = tp.Bounds.Width > 0 ? tp.Bounds.Width : 50;
        el.Height = tp.Bounds.Height > 0 ? tp.Bounds.Height : 50;
 
        Canvas.SetLeft(el, tp.Position.X - (el.Width / 2));
        Canvas.SetTop(el, tp.Position.Y - (el.Height / 2));
 
        canvMain.Children.Add(el);
        TouchEllipses.Add(e.TouchDevice.Id, el);
 
        e.Handled = true;
    }
 
    private void Canvas_TouchUp(object sender, TouchEventArgs e)
    {
        canvMain.Children.Remove(TouchEllipses[e.TouchDevice.Id]);
        TouchEllipses.Remove(e.TouchDevice.Id);
 
        e.Handled = true;
    }
}


#748 – 獲得按下時對應位置點的大小(Getting the Size of a Contact Point during Raw Touch)