我想知道如何创建一个sum + 1每 5 秒添加一次的标签?我尝试过使用 if 循环,但不幸的是它在一秒钟后重置。
using System.Diagnostics;
// using system.diagnotics voor stopwatch
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Stopwatch sw = new Stopwatch();
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
sw.Start();
if (timer1.Enabled == true) { button1.Text = "stop"; }
else { button1.Text = "false"; sw.Stop(); }
}
private void timer1_Tick(object sender, EventArgs e)
{
int hours = sw.Elapsed.Hours;
int minutes = sw.Elapsed.Minutes; …Run Code Online (Sandbox Code Playgroud) 我做了这个小嵌套for循环,并且它在C#中没有显示任何错误,但是当我尝试运行我的小程序时,我得到以下错误TextBox:
System.Windows.Forms.TextBox,Text:System.Windows.Forms.TextBox,Text:Syst ...
这是我的代码:
int number = textBox.Text..ToString();
for (int row = 0; row < number; row++)
{
for (int x = number - row; x > 0; x--)
{
textBox2.Text = textBox2.Text + "X";
}
textBox2.Text = textBox2 + Environment.NewLine;
}
Run Code Online (Sandbox Code Playgroud)
我的结果应该是这样的:
XXXX
XXX
XX
X.
我无法弄清楚可能导致此错误的原因.