The PointerEventArgs.DeviceType property indicates the type of device used in the event handler. The property returns Touch for finger and Pen for Pen device.
1. Ensure your device supports the Pen device.
2. Create a new Windows Forms Application Project.
3. Add a Standard Button control and a C1TouchEventProvider control to the Form.
4. Use the following code:
[C#]
using C1.Win.TouchToolKit;
private void Form1_Load(object sender, EventArgs e) { c1TouchEventProvider1.SetEnableTouchEvents(button1, true); c1TouchEventProvider1.Tapped += c1TouchEventProvider1_Tapped; button1.Click += button1_Click; }
private void c1TouchEventProvider1_Tapped(object sender, TappedEventArgs e) { if (e.TargetControl == this.button1) { if (e.PointerDeviceType == PointerDeviceType.Touch) { MessageBox.Show("Pressed by Touch"); } else if (e.PointerDeviceType == PointerDeviceType.Pen) { MessageBox.Show("Pressed by Pen"); } } }
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Pressed by Mouse"); } |
[Visual Basic]
Imports C1.Win.TouchToolKit
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load C1TouchEventProvider1.SetEnableTouchEvents(Button1, True) End Sub
Private Sub C1TouchEventProvider1_Tapped(sender As System.Object, e As TappedEventArgs) Handles C1TouchEventProvider1.Tapped If e.TargetControl Is Button1 Then If e.PointerDeviceType = PointerDeviceType.Touch Then MessageBox.Show("Pressed by Touch") ElseIf e.PointerDeviceType = PointerDeviceType.Pen Then MessageBox.Show("Pressed by Pen") End If End If End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click MessageBox.Show("Pressed by Mouse") End Sub |