110,534
社区成员
发帖
与我相关
我的任务
分享
//界面控件textBox1,textBox2,button1,timer1,timer2
public partial class Form1 : Form
{
public bool flag = false;
public int a = 0;
public int b = 0;
public static string[] txta = { "1", "2", "4", "5", "8", "9" };
public static string[] txtb = { "2", "3", "4", "6", "8", "11" };
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
textBox1.Text = txta[a].ToString();
a++;
a = a % 6;
}
private void timer2_Tick(object sender, EventArgs e)
{
textBox2.Text = txtb[b].ToString();
b++;
b=b%6;
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer2.Interval = 1000;
}
private void button1_Click(object sender, EventArgs e)
{
flag = !flag;
if (flag)
{
timer1.Start();
timer2.Start();
}
else
{
timer1.Stop();
timer2.Stop();
textBox1.Text = "接收数据";
textBox2.Text = "接收数据";
}
}
}