请问C#中如何实现点击一个按钮使别的控件上移或下移或左移或右移?
1个回答
展开全部
我给你一个例子,这个是使用按钮控制一个图片移动,其它控件可以参照此例:
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);
}
}
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);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询