簡體   English   中英

文本框不會更新總數

[英]Textbox won't update total

我正在嘗試在文本框中顯示總計,但是只有在分配給它的值大於最后一個值而不是添加到最后一個值時,文本框輸出的變量才會更新。

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.");
}

左下角的文本框

文本框不添加

如果值更大則更新

GI1 是對的,只是需要在事件之外聲明的變量

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM