0

我正在使用 C# 在 Visual Studio 2013 中编写应用程序

我有一些从 Kinect 获得的实时值,我处理这些值并将它们保存在浮点中。

大约有 8 个值

我需要在我的窗口上打印这些值我该怎么做?

4

1 回答 1

0

如果您只需要在 Window 上显示不断变化的浮点数,您可以使用Label. 但由于值经常更改,这可能会导致 GUI 挂起。为了防止这种情况,我有一个扩展类

public static class CrossThreadExtensions
{
    public static void PerformSafely(this Control target, Action action)
    {
        if (target.InvokeRequired)
        {
            target.Invoke(action);
        }
        else
        {
            action();
        }
    }

    public static void PerformSafely<T1>(this Control target, Action<T1> action, T1 parameter)
    {
        if (target.InvokeRequired)
        {
            target.Invoke(action, parameter);
        }
        else
        {
            action(parameter);
        }
    }

    public static void PerformSafely<T1, T2>(this Control target, Action<T1, T2> action, T1 p1, T2 p2)
    {
        if (target.InvokeRequired)
        {
            target.Invoke(action, p1, p2);
        }
        else
        {
            action(p1, p2);
        }
    }
}

并以这种方式使用

值更改事件:

Thread erThread = new Thread(delegate()
{
    label1.PerformSafely(() => label1.Text = _YourFloatingPointValue.ToString());
});
erThread.Start();
erThread.IsBackground = true;
于 2014-12-29T07:37:05.063 回答