我在做一个打字游戏
用timer 生成label
private void timer1_Tick(object sender, EventArgs e)
{
Label _label = new Label();
..............省略;
}
现在我需要控制Label 如果我输入正确则Label 消失
应该如何访问 Label 我如何在KeyDown中获取Label的Text 值.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
.......省略;
}另外. 消失用 Enabled ???
用timer 生成label
private void timer1_Tick(object sender, EventArgs e)
{
Label _label = new Label();
..............省略;
}
现在我需要控制Label 如果我输入正确则Label 消失
应该如何访问 Label 我如何在KeyDown中获取Label的Text 值.
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
.......省略;
}另外. 消失用 Enabled ???
不就可以了?
我就是想在 KeysDown 中让Label 消失..但我不能访问.
如何解决...
小白点...勿见怪
Random r1 = new Random(unchecked((int)DateTime.Now.Ticks));
Random r2 = new Random();
int R1 = r1.Next(65, 90);
int R2 = r2.Next(0, 12);
_label.AutoSize = true;
_label.Location = new System.Drawing.Point(R2*60+30,50);
_label.Name = Convert.ToChar(R1).ToString();
_label.Size = new System.Drawing.Size(41, 12);
_label.Text = Convert.ToChar(R1).ToString();
this.Controls.Add(_label);生成的label 在KeysDown 中如何访问. 让其消失
不过不会用 controls 试试..
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void t1_Tick(object sender, EventArgs e)
{
Label label1 = new Label();
label1.AutoSize = true;
label1.BackColor = System.Drawing.Color.Transparent;
label1.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
label1.ForeColor = System.Drawing.Color.Fuchsia;
Random r = new Random();
label1.Location = new System.Drawing.Point(r.Next(this.pnl.Left+23,this.pnl.Right-23), 12);
label1.Name = "label1";
label1.Size = new System.Drawing.Size(22, 24);
label1.TabIndex = 0;
int a1 = (int)'a';
int a2 = (int)'z';
label1.Text = ((char)r.Next(a1,a2)).ToString();
int a = this.gb.Top;
Runs runs = new Runs(label1,a);
runs.startm();
this.pnl.Controls.Add(label1);
} private void button1_Click(object sender, EventArgs e)
{
this.t1.Enabled = true;
this.txt1.Focus();
} private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
Thread.CurrentThread.Abort();
}
private void button2_Click(object sender, EventArgs e)
{ } private void txt1_KeyPress(object sender, KeyPressEventArgs e)
{
foreach (Label obj in this.pnl.Controls)
{
if (e.KeyChar.ToString().Equals(obj.Text.ToString()))
{
obj.Visible = false;
this.lbl.Text = "对";
break;
}
else
{
this.lbl.Text = "错";
}
}
}
}
}
class Runs
{
private Label _label1;
private Thread m;
private int i;
public Runs(Label label1,int i)
{
this._label1 = label1;
this.i = i;
}
public void startm()
{
m = new Thread(new ThreadStart(move));
m.Start();
}
public void move()
{
int a=4;
while (true)
{
if (_label1.Top >=i)
{
this._label1.Dispose();
m.Abort();
}
_label1.Top += a;
Thread.Sleep(50);
}
}
}
pnl 是什么.
另外给分了这个贴就不能回复了???
[email protected]
我用KeyDown 事件没问题吧.
好像哪里写错了...
没反应.....