C# 单击按钮后如何使用变量
我被我的程序卡住了。我有这部分代码:C# 单击按钮后如何使用变量,c#,.net,variables,event-handling,C#,.net,Variables,Event Handling,我被我的程序卡住了。我有这部分代码: public void PacketArrival(ref IntPtr ContextHandle, ref int Cursor_Renamed, ref int X , ref int Y , ref int Z, ref int Buttons, ref int Pressure , ref int TangentPressure, ref int Azimuth, ref
public void PacketArrival(ref IntPtr ContextHandle, ref int Cursor_Renamed,
ref int X , ref int Y , ref int Z, ref int Buttons,
ref int Pressure , ref int TangentPressure, ref int Azimuth,
ref int Altitude, ref int Twist, ref int Pitch , ref int Roll ,
ref int Yaw,ref int PacketSerial, ref int PacketTim)
{
tmpl = System.Math.Abs(X);
if( tmpl != prgX.Value)
{
if( tmpl <= prgX.Maximum )
prgX.Value = tmpl;
}
tmpl = System.Math.Abs(Y);
if( tmpl != prgY.Value)
{
if( tmpl <= prgY.Maximum)
prgY.Value = tmpl;
}
tmpl = System.Math.Abs(Z);
if( tmpl != prgZ.Value)
{
if( tmpl <= prgZ.Maximum)
prgZ.Value = tmpl;
}
tmpl = System.Math.Abs(Pressure);
if( tmpl != prgPressure.Value)
prgPressure.Value = tmpl;
if( Convert.ToInt32(lblX.Text)!= X )
lblX.Text = X.ToString();
if( Convert.ToInt32(lblY.Text)!= Y )
lblY.Text = Y.ToString();
if( Convert.ToInt32(lblZ.Text)!= Z )
lblZ.Text = Z.ToString();
if( Convert.ToInt32(lblPressure.Text)!= Pressure )
lblPressure.Text = Pressure.ToString();
if (Pressure !=0)
{
File.AppendAllText("test2.txt", Pressure.ToString() + Environment.NewLine);
}
label1.Text = Pressure.ToString();
}
但我总是得到0作为值。对不起,我的英语不好
压力只出现在代码的第一部分,并没有其他地方。如您所见,压力也写入文件中,但当我想在单击按钮后使用它时,它始终显示0
p、 s.label1显示正确的值我解决了它。问题出在第二个函数中。我需要使用按钮鼠标向下事件。哪里定义了
prgPressure
?它是如何定义的?在哪里设置该值?还有什么地方可能会被设置?当你调试这个时,这个值具体丢失在哪里?另外请解释为什么你在a)你不在任何地方更改它们,b)你甚至不使用它们的时候用ref传递很多参数对不起,我的错,我不需要prgPressure。值,我需要压力。告诉我们如何定义Pressure
变量。您只需在PackedArrival()
digitalizer.PacketArrival+=new Tablet.PacketArrivalEventHandler(PacketArrival)中引用它即可;
private void button2_Click(object sender, EventArgs e)
{
label5.text = Pressure.ToString();
}