Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
87 views
in Technique[技术] by (71.8m points)

c# - Textbox won't update total

I'm trying to display a total in a text box however the variable the text box outputs will only update if the value assigned to it is greater than the last value instead of adding to the last value.

private void PictureBoxWindFarmMouseClick(object sender, MouseEventArgs e)
{
  decimal captot = 0;
  // Read mouse-click position
  int x = e.X;
  int y = e.Y;
  //collects varibles from the form 
  int hei = _heightTrackBar.Value;
  float rad = (_radiusTrackBar.Value)*0.01f ;
  int bla = Convert.ToInt32(_numberOfBladesUpDown.Value);
  Color pol = colorDialog1.Color;
  Color rot = colorDialog2.Color;
  bool clo = _clockwiseCheckBox.Checked;
  decimal cap = _capacityUpDown.Value;
  captot +=  cap;
  // Create wind turbine at this position, uses collected varibles
  WindTurbine turbine = new WindTurbine( hei, rad, bla, clo, pol, rot, cap, x, y);
  // Add wind turbine to farm list
  _turbines.Add(turbine);
  // Force redraw of the picture box to show changes
  _pictureBoxWindFarm.Refresh();
  _statusLabel.ResetText();
  _statusLabel.Text = ("these"+ _turbines.Count + "wind turbines can generate a total of" + captot + "MW of power.");
}

textbox at lower left

textbox not adding

updates if value is greater

question from:https://stackoverflow.com/questions/65648758/textbox-wont-update-total

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

GI1 was right the variable just needed to be declared outside the event


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...