你如何让图片框在表格中移动? [英] How do you make a picture box move around the form?

查看:137
本文介绍了你如何让图片框在表格中移动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在带有一个图片框和一个按钮的C#表单中。

单击按钮,图片框应该从表单的一个边缘移动到表单周围的另一个边缘?



请尽可能提供简单的代码



我尝试过:



private void timer1_Tick(object sender,EventArgs e)

{

int x = _random.Next (1,2);

int y = _random.Next(1,2);



pictureBox1.Left + = x;



if(pictureBox1.Location = new Point(180,0))

{

pictureBox1.Top + = y;

}

else if(pictureBox1.Location = new Point(180,160)

{

pictureBox1.Left + = -x;

}



我的所有尝试都失败了。#feelinghopeless

In a C# form with one picturebox and one button.
by clicking the button, picture box should move from one edge of the form to another edge around the form?

Please provide simple code if possible

What I have tried:

private void timer1_Tick(object sender, EventArgs e)
{
int x = _random.Next(1, 2);
int y = _random.Next(1, 2);

pictureBox1.Left += x;

if (pictureBox1.Location = new Point(180, 0))
{
pictureBox1.Top += y;
}
else if (pictureBox1.Location = new Point(180, 160)
{
pictureBox1.Left += -x;
}

I've failed in all my attempts. #feelinghopeless

推荐答案

使用计时器,然后在按钮中启动它。

在Tick事件中,少量更改PictureBox的Top和Left属性 - 更改越多, 跳跃的形象运动。记得查看它的容器边缘:上升时上升0,左上角时左边0,下降时顶部+高度与高度,向右移动时左边+宽度与宽度。



但这是你的作业,所以我不给你任何代码!
Use a Timer, and start it in the button.
In the Tick event, change the Top and Left properties of the PictureBox a small amount - the more the change, the "jumpier" the image movement. Remember to check for the edges of it's container: Top vs 0 when going up, Left vs 0 when going left, Top + Height vs Height when going down, Left + Width vs Width when going right.

But this is your homework, so I'll give you no code!


这篇关于你如何让图片框在表格中移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆