如何用C# picturebox的图片 移动,从这个位置曲线移动到那个位置,而且运动必须连续,不能瞬移
展开全部
string f = "w";
private void MoveForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.W)
{
if (p == 0)
{
f = "w";
timer1.Enabled = true;
}
}
if (e.KeyCode == Keys.S)
{
if (p == 0)
{
f = "s";
timer1.Enabled = true;
}
}
if (e.KeyCode == Keys.A)
{
if (p == 0)
{
f = "a";
timer1.Enabled = true;
}
}
if (e.KeyCode == Keys.D)
{
if (p == 0)
{
f = "d";
timer1.Enabled = true;
}
}
if (e.KeyCode == Keys.Q)
{
if (p == 0)
{
btnMovesQ();
}
}
if (e.KeyCode == Keys.E)
{
if (p == 0)
{
btnMovesE();
}
}
}
int p = 0;
private void timer1_Tick(object sender, EventArgs e)//Timer触发时间为1毫秒
{
if (p >= 40)
{
p = 0;
timer1.Enabled = false;
}
else
{
MoveByC(Cursor, f);
p += 5;
}
}
private void MoveByC(Control c, string fx)//任意控件移动
{
if (fx == "w")
c.Location = new Point(c.Location.X, c.Location.Y - 5);
else if (fx == "s")
c.Location = new Point(c.Location.X, c.Location.Y + 5);
else if (fx == "a")
c.Location = new Point(c.Location.X - 5, c.Location.Y);
else if (fx == "d")
c.Location = new Point(c.Location.X + 5, c.Location.Y);
}
更多追问追答
追问
还有个问题,能不能控制picturebox 四个顶点的位置啊 ,比如轨迹是弧线
追答
什么意思,没太明白,你说的是4个顶点是不是,picturebox的左上角 左下角 右上角 右下角?
你说的控制是什么意思?
快点回答啊 我要下班了
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
2014-10-31
展开全部
用定时器控件,100ms移动一下
示例代码如下:
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = false;
timer1.Interval = 100;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pictureBox1.Left < (this.Width - pictureBox1.Width))
{
pictureBox1.Left += 10;
}
else
{
pictureBox1.Left = 0;
}
}
示例代码如下:
private void Form1_Load(object sender, EventArgs e)
{
timer1.Enabled = false;
timer1.Interval = 100;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (pictureBox1.Left < (this.Width - pictureBox1.Width))
{
pictureBox1.Left += 10;
}
else
{
pictureBox1.Left = 0;
}
}
更多追问追答
追问
还有个问题,能不能控制picturebox 四个顶点的位置啊 ,比如轨迹是弧线
追答
赞同小七的回答
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询