c# - 文本框不会更新总数
问题描述
我正在尝试在文本框中显示总计,但是只有在分配给它的值大于最后一个值而不是添加到最后一个值时,文本框输出的变量才会更新。
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 是对的,只是需要在事件之外声明的变量
推荐阅读
- angular - Asp.net Core 和 Angular 7 Cors
- regex - 正则表达式 while 循环内的代码块正在工作,但在手动终止之前不显示结果
- python - 如何获取在 Python 中使用函数参数的变量的字符串版本?
- node.js - 使用 Cloudinary 从文本创建图像,不读取样式参数
- optimization - 无法最小化功能
- python - 在 Django Rest Framework 的 ListAPIView 中使用 URL 中的字段进行过滤
- python - UnicodeDecodeError:“utf-8”编解码器无法解码位置 8 中的字节 0xa0
- hive - HQL 失败 sqlexception
- mysql - 联合不存在的表的问题
- python - 是否有设置 numpy.linspace 精度的参数?