用C#实现 label字体在windows窗体里飘动(碰到边反弹)
求增加一个button,按button时,label飘动速度增加的代码privatevoidbutton_Click(objectsender,EventArgse){(...
求增加一个button,按button时,label飘动速度增加的代码
private void button_Click(object sender, EventArgs e)
{
(求代码)
} 展开
private void button_Click(object sender, EventArgs e)
{
(求代码)
} 展开
2个回答
展开全部
让子弹飞啊 ,试试下面的:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 10;
}
void timer1_Tick(object sender, EventArgs e)
{
if(label1.Location.X<label1.Parent.ClientRectangle.Width)
{
label1.Location = new Point(label1.Location.X + 2, label1.Location.Y);
}
else
{
label1.Location = new Point(0, label1.Location.Y);
}
Console.WriteLine("Location.X->" + label1.Location.X);
}
private void button1_Click(object sender, EventArgs e)
{
if (timer1.Enabled)
timer1.Enabled = false;
else
timer1.Enabled = true;
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 10;
}
void timer1_Tick(object sender, EventArgs e)
{
if(label1.Location.X<label1.Parent.ClientRectangle.Width)
{
label1.Location = new Point(label1.Location.X + 2, label1.Location.Y);
}
else
{
label1.Location = new Point(0, label1.Location.Y);
}
Console.WriteLine("Location.X->" + label1.Location.X);
}
private void button1_Click(object sender, EventArgs e)
{
if (timer1.Enabled)
timer1.Enabled = false;
else
timer1.Enabled = true;
}
}
2012-03-29
展开全部
来你妹!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询