我有一个带有按钮的表单。此应用程序旨在在触摸屏计算机上运行。单击按钮时,我想知道它是由鼠标还是触摸屏单击的。
这可能吗?如果是,怎么办?
最佳答案
private void button_Click(object sender, EventArgs e)
{
try
{
((MouseEventArgs)e).Button.ToString();
}
catch(Exception)
{
//If an exception is catch, it means the mouse was not used.
}
}
这是一种粗暴的做法,因为它会在任何时候通过鼠标以外的其他东西(触摸屏或键盘的返回)“单击”按钮时捕获异常。但它会完成工作:)
关于c# - 如何判断哪个物理设备在 C# 中单击了按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3578661/