【发布时间】:2018-06-26 15:29:37
【问题描述】:
我在 C# Form 应用程序中编写了以下代码,我试图从 Leap Motion 设备获取 x,y 和 z 坐标。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//controller.EventContext = WindowsFormsSynchronizationContext.Current;
button1.Click += new EventHandler(button1_Click);
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
// Initialize the Controller object which connects to the Leap motion service
// and captures the hand tracking data
Controller controller = new Controller();
//Get the most recent tracking data using the Frame object
Frame frame = controller.Frame();
for (int h = 0; h < frame.Hands.Count; h++)
{
// Initialize the Hand in the given frame
Hand leapHand = frame.Hands[h];
// Get the "Pointer" finger of current hand which refers to where a person is pointing
Finger leapFinger = leapHand.Fingers[1];
// Prepare a vector which will store the co-ordinate values of the tip of the pointer
Vector currentPosition = leapFinger.StabilizedTipPosition;
textBox1.Text = Convert.ToString(currentPosition.x);
textBox2.Text = Convert.ToString(currentPosition.y);
textBox3.Text = Convert.ToString(currentPosition.z);
}
}
}
但是,我需要显式单击 button1 才能显示。
知道有什么问题吗?
【问题讨论】:
-
不清楚您的问题是什么。您是否希望无需实际单击按钮即可显示坐标?
-
你为什么不打电话给
button1_Click? -
我想在不手动点击按钮的情况下调用按钮1的点击事件。我试过 button1.PerformClick() ,它不起作用
-
@sous2817 是的
-
您还希望代码如何执行?使用不同的事件...必须有触发代码运行的东西。
标签: forms visual-studio c#-4.0 onclick