【问题标题】:Can i access DrawContext variable globally? ( in any class of my app)我可以全局访问 DrawContext 变量吗? (在我的应用程序的任何类别中)
【发布时间】:2012-10-03 14:28:03
【问题描述】:

我的编程技术不太好,他们对 C# 还是很业余 我想问一下 Draw_Context 我在这里做的是找出关节之间的角度......我想做的是当角度在 70 到 90 之间时计时器开始并使用 Drawcontext.DrawText 方法在屏幕上显示任何消息 但如您所见,我无法访问 on_time_event 中的绘图变量 如果我尝试引入 DrawContext 的新变量并为其分配 draw 值...它给出了异常...因为 Draw 上下文的新变量从未分配过值 我应该怎么办? 请在这方面提供任何帮助,我将非常有帮助

 class angle
  {
    System.Timers.Timer timer = new System.Timers.Timer();
    bool timer_start = false;
    int index = 5; 
    public DrawingContext draw_contex;


  public void angle_between_left_shoulder(Skeleton sk1, DrawingContext draw, JointType    
  Shoulder_cntre, 
        JointType Shoulder_left, JointType Elbow_left, KinectSensor sen)
    {

        //draw_contex= draw;
        Joint sh_cntr = sk1.Joints[Shoulder_cntre];
        Joint sh_left = sk1.Joints[Shoulder_left];
        Joint elb_left = sk1.Joints[Elbow_left];

        Vector3 v_shoulder = new Vector3(sh_cntr.Position.X, sh_left.Position.Y, 
        sh_cntr.Position.Z);
        Vector3 v_should_l = new Vector3(sh_left.Position.X, sh_left.Position.Y, 
        sh_left.Position.Z);
        Vector3 v_elbow_l = new Vector3(elb_left.Position.X, elb_left.Position.Y, 
        elb_left.Position.Z);

        Vector3 va = v_shoulder - v_should_l;
        Vector3 vb = v_elbow_l - v_should_l;

        va = Vector3.Normalize(va);
        vb = Vector3.Normalize(vb);

        float len_prod = va.Length() * va.Length();
        float dot_pro = Vector3.Dot(va, vb);
        double angle = Math.Acos(dot_pro);

        angle = angle * 180 / Math.PI;
        angle = 180 - angle;

        System.Windows.Point shoul_l = this.point_toScreen(sh_left.Position, sen);
        draw.DrawText(new FormattedText(angle.ToString("0"), new 
         System.Globalization.CultureInfo("en-us"),
         FlowDirection.LeftToRight,
         new Typeface("Verdana"), 16, Brushes.OrangeRed),
         new System.Windows.Point(shoul_l.X+10, shoul_l.Y +20));

        if (angle > 70 && angle < 90)
        {
            if (timer_start == false)
            {

                timer.Interval = 2000;
                timer.Start();
                timer.Elapsed += new ElapsedEventHandler(on_time_event);




            }
        }
    }

    void on_time_event(object sender, ElapsedEventArgs e)
     {
      --index;
       if (index != 0)
       {

        MessageBox.Show(index.ToString());

        /*
         draw_contex.DrawText(new FormattedText(index.ToString("0"), new 
        System.Globalization.CultureInfo("en-us"),
             FlowDirection.LeftToRight,
             new Typeface("Verdana"), 16, Brushes.OrangeRed),
             new System.Windows.Point(10, 120));
       }
      else
       {
        timer.Stop();
       }

【问题讨论】:

    标签: c# kinect drawingcontext


    【解决方案1】:

    如果您只想在窗口中显示格式化字符串,您可以写入 TextBlock。在您的 XAML 中,您将拥有以下内容:

    <Grid>
      <!-- whatever other controls you have -->
      <TextBlock Name="MyMessage" />
    </Grid>
    

    然后在您的代码隐藏中,您可以将一个新字符串写入 TextBlock:

    MyMessage.Text = "You moved too soon!";
    

    您也可以轻松地格式化字符串并将其发送到该字符串。

    另外,如果我在您之前关于此主题的问题中的回答有用,请接受。将不胜感激! :) body joints angle using kinect (checking time interval)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 2012-05-14
      相关资源
      最近更新 更多