C# 我可以全局访问DrawContext变量吗?(在我的应用程序的任何类别中)
我的编程技能不太好,而且在C语言方面仍然非常业余# 我想问一下Draw_Context我在这里做的是找出关节之间的角度。。。我想做的是当角度在70到90之间时,计时器启动,并使用Drawcontext.DrawText方法在屏幕上显示任何消息 但正如您所看到的,我无法访问on_time_事件中的draw变量 如果我尝试引入一个新的DrawContext变量并为其赋值draw。。。它给出了一个例外。。。因为绘图上下文的新变量从未赋值 我该怎么办? 请在这方面给我任何帮助,我会很有帮助的C# 我可以全局访问DrawContext变量吗?(在我的应用程序的任何类别中),c#,kinect,drawingcontext,C#,Kinect,Drawingcontext,我的编程技能不太好,而且在C语言方面仍然非常业余# 我想问一下Draw_Context我在这里做的是找出关节之间的角度。。。我想做的是当角度在70到90之间时,计时器启动,并使用Drawcontext.DrawText方法在屏幕上显示任何消息 但正如您所看到的,我无法访问on_time_事件中的draw变量 如果我尝试引入一个新的DrawContext变量并为其赋值draw。。。它给出了一个例外。。。因为绘图上下文的新变量从未赋值 我该怎么办? 请在这方面给我任何帮助,我会很有帮助的 clas
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();
}
类角度
{
System.Timers.Timer Timer=新的System.Timers.Timer();
bool timer_start=false;
int指数=5;
公共绘图上下文绘图上下文;
左肩之间的公共空隙角度(骨架sk1,DrawingContext draw,JointType
肩胛骨,
接头类型肩部(左),接头类型弯头(左,Kinect传感器传感器)
{
//draw_contex=draw;
接头sh_cntr=sk1.接头[肩部];
左肩关节=sk1。左肩关节;
左肘关节=sk1。左肘关节;
Vector3 v_肩部=新Vector3(sh_中心位置.X,sh_左侧位置.Y,
位置Z);
Vector3 v_应_l=新的Vector3(sh_left.Position.X,sh_left.Position.Y,
sh_左位置Z);
Vector3 v_弯头_l=新的Vector3(elb_left.Position.X,elb_left.Position.Y,
elb_左位置Z);
向量3 va=v_肩部-v_应;
向量3 vb=v_弯头-v_应;
va=矢量3.标准化(va);
vb=矢量3.标准化(vb);
浮动长度=va.Length()*va.Length();
float dot_pro=Vector3.dot(va,vb);
双角度=数学Acos(dot_pro);
角度=角度*180/Math.PI;
角度=180-角度;
System.Windows.Point shoul_l=此点到屏幕(sh_left.Position,sen);
draw.DrawText(新格式化文本(angle.ToString(“0”),新
系统、全球化、文化信息(“en-us”),
FlowDirection.LeftToRight,
新字体(“Verdana”),16号,画笔,橙色,
新系统.Windows.Point(shoul_.X+10,shoul_.Y+20);
如果(角度>70和角度<90)
{
如果(计时器启动==错误)
{
时间间隔=2000;
timer.Start();
timer.appeased+=新的ElapsedEventHandler(on_time_事件);
}
}
}
时间事件无效(对象发送方,ElapsedEventArgs e)
{
--指数;
如果(索引!=0)
{
Show(index.ToString());
/*
draw_contex.DrawText(新格式化文本(index.ToString(“0”),新
系统、全球化、文化信息(“en-us”),
FlowDirection.LeftToRight,
新字体(“Verdana”),16号,画笔,橙色,
新系统。Windows。点(10120));
}
其他的
{
timer.Stop();
}
如果您只想在窗口中显示格式化的字符串,您可以将其写入文本块。在XAML中,您可以看到以下内容:
<Grid>
<!-- whatever other controls you have -->
<TextBlock Name="MyMessage" />
</Grid>
您可以同样轻松地格式化字符串并将其发送到该字符串
另外,如果我在你上一个问题中对这个问题的回答是有用的,请接受。我们将不胜感激!:)
MyMessage.Text = "You moved too soon!";