发布网友 发布时间:2022-04-24 02:36
共2个回答
热心网友 时间:2023-10-22 08:09
在Form1窗体中,
有一个TextBox文本控件名为txtShow
有2个按钮:开始 btnStart 和 结束 btnStop
一个时钟控件名为 timer1
int i = 0;//成员变量,用来取数组中固定索引的值
string[] str = new string[] { "aaa", "bbb", "ccc" };
//开始按钮被单击
private void btnStart_Click(object sender, EventArgs e)
{
timer1.Start();
}
//结束按钮被单击
private void btnStop_Click(object sender, EventArgs e)
{
timer1.Stop();
}
//在文本控件中显示字符串
private void timer1_Tick(object sender, EventArgs e)
{
txtShow.Text = str[i];
if (i == 2) //当str的索引为2时说明数组以循环完毕,赋初值0,
i = 0;
else
i++;
}
//窗体加载时,设置时钟事件的发生频率
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;//设置时钟事件的频率为1000毫秒
}
热心网友 时间:2023-10-22 08:09
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 WindowsForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
string[] arr=new string[3];
arr[0] = "aaa";
arr[1] = "bbb";
arr[2] = "ccc";
textBox1.Text = arr[i];
i++;
while (i == 3) { i = 0; }
}
private void butStart_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void butStop_Click(object sender, EventArgs e)
{
timer1.Stop();
}
}
}
给分呗.....