C# 打字游戏 大小写字母,数字能一起出现
privatevoidtimer1_Tick(objectsender,EventArgse){LabelI=newLabel();charcc=(char)((int)...
private void timer1_Tick(object sender, EventArgs e)
{
Label I = new Label();
char cc = (char)((int)'a' + r.Next(26)); //随机产生26 个字母
I.Text = cc.ToString();
I.Left = r.Next(this.Width);//随机水平位置
this.Controls.Add(I);
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Label))
{
c.Top += 15;//向下移动
if (c.Top == this.Height)c.Dispose();//到底消除
}
}
}
如何在此事件里添加程序语句能够实现界面上同时出现大小写字母,最好也能有数字出现,现在的程序只能出现小写字母,哪位高手能帮下小弟,谢谢了! 展开
{
Label I = new Label();
char cc = (char)((int)'a' + r.Next(26)); //随机产生26 个字母
I.Text = cc.ToString();
I.Left = r.Next(this.Width);//随机水平位置
this.Controls.Add(I);
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Label))
{
c.Top += 15;//向下移动
if (c.Top == this.Height)c.Dispose();//到底消除
}
}
}
如何在此事件里添加程序语句能够实现界面上同时出现大小写字母,最好也能有数字出现,现在的程序只能出现小写字母,哪位高手能帮下小弟,谢谢了! 展开
展开全部
private void timer1_Tick(object sender, EventArgs e)
{
//存储所有可能出现的值,A-Z,a-z,0-9,这里只写部分,你可以自己加上
ArrayList labelTexts = new ArrayList() { "A", "B","a","b", 1, 2 };
Label label = new Label();
Random ran = new Random();
string labelText = labelTexts[ran.Next(labelTexts.Count-1)].ToString();//产生随机数,并取出labelTexts数组中对应索引的值
label.Text = labelText;
label.Left = ran.Next(this.Width);//随机水平位置
this.Controls.Add(label);
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Label))
{
c.Top += 15;//向下移动
if (c.Top == this.Height) c.Dispose();//到底消除
}
}
}
{
//存储所有可能出现的值,A-Z,a-z,0-9,这里只写部分,你可以自己加上
ArrayList labelTexts = new ArrayList() { "A", "B","a","b", 1, 2 };
Label label = new Label();
Random ran = new Random();
string labelText = labelTexts[ran.Next(labelTexts.Count-1)].ToString();//产生随机数,并取出labelTexts数组中对应索引的值
label.Text = labelText;
label.Left = ran.Next(this.Width);//随机水平位置
this.Controls.Add(label);
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(Label))
{
c.Top += 15;//向下移动
if (c.Top == this.Height) c.Dispose();//到底消除
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询