C#,为什么picturebox1不移动啊!!!! 5
publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}intflagLeftRight=0;...
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int flagLeftRight = 0;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A)
{ flagLeftRight = -1; }
if (e.KeyCode == Keys.D)
{ flagLeftRight = 1; }
}
private void timer1_Tick(object sender, EventArgs e)
{
if (flagLeftRight == -1 && pictureBox1.Left > pictureBox2.Left)
{ pictureBox1.Left--; }
}
} 展开
{
public Form1()
{
InitializeComponent();
}
int flagLeftRight = 0;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A)
{ flagLeftRight = -1; }
if (e.KeyCode == Keys.D)
{ flagLeftRight = 1; }
}
private void timer1_Tick(object sender, EventArgs e)
{
if (flagLeftRight == -1 && pictureBox1.Left > pictureBox2.Left)
{ pictureBox1.Left--; }
}
} 展开
展开全部
程序应该没有问题,可以有两个属性你没有设置,应该设置如下属性 :
this.timer1.Enabled = true;//启动Timer控件
this.Form1.KeyPreview = true;//设置键盘事件向窗体注册
this.timer1.Enabled = true;//启动Timer控件
this.Form1.KeyPreview = true;//设置键盘事件向窗体注册
追问
还是不行啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询