请帮忙 [英] Pls help
问题描述
如何用按钮更改int值?请使用系统帮助
;使用System.Collections.Generic获取
;使用System.ComponentModel获得
;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
命名空间WindowsFormsApp5
{
 公共部门类Form1:表格
  {
      public Form1()
      {
          InitializeComponent();
      }¥b $ b       int value =(1);
      private void button1_Click(object sender,EventArgs e)
      {
          int value =(value)+1;
          string value2 = Convert.ToString(value);
          label1.Text =(value2);
      }
      private void label1_Click(object sender,EventArgs e)
      {
$
      }¥b $ b   }
}
您的基本想法看起来是正确的。
我能看到的唯一问题是你已经声明了一个名为"value"的变量。在方法中,也存在于类级别。我认为这是一个错误,你希望方法中的代码实际上引用"值"。在类级声明的变量
:
private void button1_Click(object sender,EventArgs e)
{
value = value + 1; //只需使用"价值" (不要用"int"重新声明)
string value2 = Convert.ToString(value);
label1.Text =(value2);
}
作为一个有用的提示。
value = value + 1;
可以改写为:
value ++;
how do i change int value with button ? pls help
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int value = (1);
private void button1_Click(object sender, EventArgs e)
{
int value = (value)+1;
string value2 = Convert.ToString(value);
label1.Text = (value2);
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Your basic idea looks correct.
The only issue I can see is that you have declared a variable called "value" within the method, which also exists at the class level. I assume this is a mistake and you want the code in the method to actually refer to the "value" variable declared at the class level:
private void button1_Click(object sender, EventArgs e) { value = value+1; // just use "value" (do not re-declare with "int") string value2 = Convert.ToString(value); label1.Text = (value2); }As a helpful hint.
value = value +1;
can be rewritten as:
value ++;
这篇关于请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!