c# - 使用 touchDown 在 Datagrid 中模拟双击事件

标签 c# wpf datagridview mouse emulation

我是 WPF 新手。我有一个带有数据网格的 WPF 窗口,它在双击时启动一个进程。这很好用,但是当我在平板电脑(带有 Windows 7)中使用触摸屏执行此操作时,该过程永远不会发生。所以我需要用触摸事件模拟双击事件。任何人都可以帮助我做到这一点,好吗?

最佳答案

参见 How to simulate Mouse Click in C#?有关如何模拟鼠标单击(在 Windows 窗体中)的信息,但它在 WPF 中的工作方式是:

using System.Runtime.InteropServices;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);

    private const int MOUSEEVENTF_LEFTDOWN = 0x02;
    private const int MOUSEEVENTF_LEFTUP = 0x04;
    private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
    private const int MOUSEEVENTF_RIGHTUP = 0x10;

    public void DoMouseClick()
    {
         //Call the imported function with the cursor's current position
        int X = //however you get the touch coordinates;
        int Y = //however you get the touch coordinates;
        mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
    }
}
}

关于c# - 使用 touchDown 在 Datagrid 中模拟双击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11442768/

相关文章:

c# - 使用 WPF 将应用程序最小化到系统托盘(不使用 NotifyIcon)

c# - DataGridView合并

c# - 使用文本框过滤列表框项目

c# - C# 程序如何使用任何版本的 COM dll?

c# - ServiceStack.Redis : Configure so that the request and response class/dto is the same class?

c# - 如何在 C# 中混合两个视频流?

wpf - 如何在 MainWindow 上显示不同的 View

c# - DataGridView 选定单元格默认颜色

c# - 如何在 C# 中将 xml 文件中的值赋给 datagridviewtextbox?

c# - 检查 String 是否可以转换为 C# 中的给定类型