自问下面的代码没有写错,,可是,为什么效果总出不来呢,求帮助。。
namespace 控件移动
{
public partial class Form1 : Form
{
public bool flag = true;
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (flag)
{//定义了布尔型的flag,为true则向右,为false则向左,
button1.Left += 4;
if (button1.Left == panel1.Width - button1.Width)
flag = false;
}
else {
button1.Left -= 4;
if (button1.Left == 0)
flag = true;
}
}