简体   繁体   中英

How to use variable after button click

I'm stuck with my program. I have this part of the code:

 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();

}

So I wanna use Pressure when I do button click

private void button2_Click(object sender, EventArgs e) 
{
    label5.text = Pressure.ToString();
}

But I always get 0 as value. Sorry on my english Pressure only appears in first part of the code, nowhere else. As you can see, Pressure is also written in the file, but when I want to use it after button click it always shows 0

ps label1 shows correct value

I solved it. The problem was in second function. I needed tu use button_MouseDown event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM