C# 如何让一个按钮每按一下,按钮里面的的text值发生变化,按六次,有六个不同的值
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Q696139
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] arr = { "a", "b", "c", "d", "e" };
int i = 0;
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = arr[i];
i = ++i % arr.Length;
}
}
}
不好意思,疏忽了一点,6个不同的值,那么在数组加上一个
string[] arr = { "a", "b", "c", "d", "e", "f" };
如果要随机,而不是顺序循环,那么
i = ++i % arr.Length;
换成
int p = i;
while (p == i)
i = new Random().Next(0, arr.Length);
另外,不知道上次 https://ask.csdn.net/questions/695236 这个问题解决了没有,如果解决了的话,麻烦给我的回答点个采纳,谢谢了。