Pointer 類別

定義

提供與單一滑鼠、手寫筆/手寫筆或觸控連絡人相關聯的輸入指標基本屬性。

public ref class Pointer sealed
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class Pointer final
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class Pointer
Public NotInheritable Class Pointer
繼承
Object Platform::Object IInspectable Pointer
屬性

範例

下列程式碼範例顯示 Pointer 類別的使用方式,以尋找應用程式中每個輸入連絡人的唯一 PointerId 、使用 PointerDeviceType 忽略特定形式的輸入 (,例如滑鼠輸入) 並儲存 Pointer 位置。 如需使用 Pointer 類別的其他程式碼,請參閱 輸入範例

using System.Collections.Generic;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;

namespace PointerExample
{
    public sealed partial class BlankPage : Page
    {
        Dictionary<uint, Point?> _contacts;
        const uint SUPPORTEDCONTACTS = 5;

        public BlankPage()
        {
            this.InitializeComponent();
            _contacts = new Dictionary<uint, Point?>((int)SUPPORTEDCONTACTS);
            this.PointerPressed += BlankPage_PointerPressed;
            this.PointerReleased += BlankPage_PointerReleased;
        }

        private void BlankPage_PointerPressed(object sender, 
            PointerRoutedEventArgs e)
        {
            // Ignore mouse inputs. 
            if (e.Pointer.PointerDeviceType != 
                Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                // Store and touch input contacts.  
                Windows.UI.Input.PointerPoint pt = e.GetCurrentPoint(this);
                _contacts[e.Pointer.PointerId] = pt.Position;
            }
            e.Handled = true;
        }

        private void BlankPage_PointerReleased(object sender, 
            PointerRoutedEventArgs e)
        {
            // Ignore mouse inputs.
            if (e.Pointer.PointerDeviceType != 
                Windows.Devices.Input.PointerDeviceType.Mouse)
            {
                // Remove pointer contacts information.
                uint ptrId = e.Pointer.PointerId;
                if (_contacts.ContainsKey(ptrId))
                {
                    _contacts[ptrId] = null;
                    _contacts.Remove(ptrId);
                }
            }
            e.Handled = true;
        }
    }
}

備註

類別 Pointer 是用來描述輸入裝置。 這個類別會識別每個發生指標事件的輸入裝置 (,例如手寫筆、手指或滑鼠) 。

在大部分情況下,建議您透過指標事件處理常式的事件引數取得指標資訊, (請參閱 PointerRoutedEventArgs) 。

如果事件引數未內建公開應用程式所需的指標詳細資料,您可以透過PointerRoutedEventArgsGetCurrentPointGetIntermediatePoints方法,存取擴充指標資料。 建議您使用這些方法,因為您可以指定指標資料的內容。

屬性

IsInContact

取得值,這個值會判斷指標裝置在報告事件時是否與感應器或數位板連絡。

IsInRange

取得值,指出指標裝置是否在感應器或數位板的偵測範圍內。

PointerDeviceType

取得指標裝置的 PointerDeviceType

PointerId

取得這個指標參考的系統產生識別碼。

適用於

另請參閱