我给你一个例子,这个是使用按钮控制一个图片移动,其它控件可以参照此例:
private static int temp;
private void btnLeft_Click(object sender, EventArgs e)
{
if (this.picShow.Location.X == 0)
{
MessageBox.Show("已经到最左边了!");
}
else
{
temp = picShow.Location.X;
temp -= 10;
picShow.Location = new Point(temp,picShow.Location.Y);
}
}
private void btnDown_Click(object sender, EventArgs e)
{
if (this.picShow.Location.Y == 430)
{
MessageBox.Show("已经到底部了!");
}
else
{
temp = picShow.Location.Y;
temp += 10;
picShow.Location = new Point(picShow.Location.X, temp);
}
}
private void btnUp_Click(object sender, EventArgs e)
{
if (this.picShow.Location.Y == 0)
{
MessageBox.Show("已经到顶部了!");
}
else
{
temp = picShow.Location.Y;
temp -= 10;
picShow.Location = new Point(picShow.Location.X, temp);
}
}
private void btnRight_Click(object sender, EventArgs e)
{
if (this.picShow.Location.X == 500)
{
MessageBox.Show("已经到最右边了!");
}
else
{
temp = picShow.Location.X;
temp += 10;
picShow.Location = new Point(temp, picShow.Location.Y);
}
}