gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:52:16 25 4
gpt4 key购买 nike

我是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com