C# 制作悬停按钮

C# 制作悬停按钮,c#,winforms,timer,C#,Winforms,Timer,我要做的是,当我按下按钮时,它应该向右移动,直到它到达标签的左侧。在我的情况下,按钮只是消失了。解决办法可能是什么 private void button1_Click(object sender, EventArgs e) { timer1.Enabled = !timer1.Enabled; } private void timer1_Tick(object sender, EventArgs e) { for (int i = 0; i < label1.Left;

我要做的是,当我按下按钮时,它应该向右移动,直到它到达标签的左侧。在我的情况下,按钮只是消失了。解决办法可能是什么

private void button1_Click(object sender, EventArgs e)
{
    timer1.Enabled = !timer1.Enabled;
}

private void timer1_Tick(object sender, EventArgs e)
{
    for (int i = 0; i < label1.Left; i++)
    {
        button1.Left += i;
    }
}
private void按钮1\u单击(对象发送者,事件参数e)
{
timer1.Enabled=!timer1.Enabled;
}
私有无效计时器1_刻度(对象发送方,事件参数e)
{
for(int i=0;i
当计时器滴答作响时,它将循环for循环一次(计时器的调用滴答作响),并将其移动到((button1.Left+label1.Left)*numberOfTicks)。
您拥有的代码与编写代码基本相同:

button1_Click(object s, EventArgs e){
  timer1.Tick += delegate(object sender, EventArgs ev){
    button1.Left += label1.Left;
  };
  timer1.Enabled = true;
}
如果你想用定时器像那样移动它,你必须设置一个时间间隔,每次定时器滴答作响时,把它移动几个像素,而不是所有像素


比如:

const int DISTANCE = 1;

void button1_Click(object s, EventArgs e){
  timer1.Enabled = true;
}

void timer1_Tick(object s, EventArgs e){
  if(button1.Left < label1.Left)      
    button1.Left += DISTANCE;
}
const int DISTANCE=1;
无效按钮1\u单击(对象、事件参数){
timer1.Enabled=true;
}
无效计时器1_刻度(对象s、事件参数e){
如果(按钮1.左<标签1.左)
按钮1.左+=距离;
}

当计时器滴答作响时,它将循环for循环一次(计时器的调用滴答作响),并将其移动到((button1.Left+label1.Left)*numberOfTicks)。
您拥有的代码与编写代码基本相同:

button1_Click(object s, EventArgs e){
  timer1.Tick += delegate(object sender, EventArgs ev){
    button1.Left += label1.Left;
  };
  timer1.Enabled = true;
}
如果你想用定时器像那样移动它,你必须设置一个时间间隔,每次定时器滴答作响时,把它移动几个像素,而不是所有像素


比如:

const int DISTANCE = 1;

void button1_Click(object s, EventArgs e){
  timer1.Enabled = true;
}

void timer1_Tick(object s, EventArgs e){
  if(button1.Left < label1.Left)      
    button1.Left += DISTANCE;
}
const int DISTANCE=1;
无效按钮1\u单击(对象、事件参数){
timer1.Enabled=true;
}
无效计时器1_刻度(对象s、事件参数e){
如果(按钮1.左<标签1.左)
按钮1.左+=距离;
}

当计时器滴答作响时,它将循环for循环一次(计时器的调用滴答作响),并将其移动到((button1.Left+label1.Left)*numberOfTicks)。
您拥有的代码与编写代码基本相同:

button1_Click(object s, EventArgs e){
  timer1.Tick += delegate(object sender, EventArgs ev){
    button1.Left += label1.Left;
  };
  timer1.Enabled = true;
}
如果你想用定时器像那样移动它,你必须设置一个时间间隔,每次定时器滴答作响时,把它移动几个像素,而不是所有像素


比如:

const int DISTANCE = 1;

void button1_Click(object s, EventArgs e){
  timer1.Enabled = true;
}

void timer1_Tick(object s, EventArgs e){
  if(button1.Left < label1.Left)      
    button1.Left += DISTANCE;
}
const int DISTANCE=1;
无效按钮1\u单击(对象、事件参数){
timer1.Enabled=true;
}
无效计时器1_刻度(对象s、事件参数e){
如果(按钮1.左<标签1.左)
按钮1.左+=距离;
}

当计时器滴答作响时,它将循环for循环一次(计时器的调用滴答作响),并将其移动到((button1.Left+label1.Left)*numberOfTicks)。
您拥有的代码与编写代码基本相同:

button1_Click(object s, EventArgs e){
  timer1.Tick += delegate(object sender, EventArgs ev){
    button1.Left += label1.Left;
  };
  timer1.Enabled = true;
}
如果你想用定时器像那样移动它,你必须设置一个时间间隔,每次定时器滴答作响时,把它移动几个像素,而不是所有像素


比如:

const int DISTANCE = 1;

void button1_Click(object s, EventArgs e){
  timer1.Enabled = true;
}

void timer1_Tick(object s, EventArgs e){
  if(button1.Left < label1.Left)      
    button1.Left += DISTANCE;
}
const int DISTANCE=1;
无效按钮1\u单击(对象、事件参数){
timer1.Enabled=true;
}
无效计时器1_刻度(对象s、事件参数e){
如果(按钮1.左<标签1.左)
按钮1.左+=距离;
}
私有无效计时器1\u勾选(对象发送方,事件参数e)
{
如果(按钮1.左<标签1.左)
{
按钮1.左++;
}
}
私有无效计时器1\u勾选(对象发送方,事件参数e)
{
如果(按钮1.左<标签1.左)
{
按钮1.左++;
}
}
私有无效计时器1\u勾选(对象发送方,事件参数e)
{
如果(按钮1.左<标签1.左)
{
按钮1.左++;
}
}
私有无效计时器1\u勾选(对象发送方,事件参数e)
{
如果(按钮1.左<标签1.左)
{
按钮1.左++;
}
}


什么是WPF??Winforms???我已经编辑了你的标题。请看“,”其中的共识是“不,他们不应该”。什么是WPF??Winforms???我已经编辑了你的标题。请看“,”其中的共识是“不,他们不应该”。什么是WPF??Winforms???我已经编辑了你的标题。请看“,”其中的共识是“不,他们不应该”。什么是WPF??Winforms???我已经编辑了你的标题。请看,“,其中的共识是“不,他们不应该”。实际上,他编写的代码将把按钮移动到距离标签的距离的平方处或某个(+=i在一个for循环中一直到label.Left)啊,是的,像“button1.Left+=label1.Left”而不是“button1.Left=label1.Left”。编辑答案:)事实上,这也远不止这些。假设Label1.Left是5,那么每次计时器触发时,它都会加上0+1+2+3+4=10。如果是10,则为0+1+2+3+4+5+6+7+8+9=45。等等……哦,是的,我甚至没想到!:)实际上,他编写的代码会将按钮移动到标签距离的平方,或者某种(+=i在一个for循环中一直到label.Left)啊,是的,比如“button1.Left+=label1.Left”而不是“button1.Left=label1.Left”。编辑答案:)事实上,这也远不止这些。假设Label1.Left是5,那么每次计时器触发时,它都会加上0+1+2+3+4=10。如果是10,则为0+1+2+3+4+5+6+7+8+9=45。等等……哦,是的,我甚至没想到!:)实际上,他编写的代码会将按钮移动到标签距离的平方,或者某种(+=i在一个for循环中一直到label.Left)啊,是的,比如“button1.Left+=label1.Left”而不是“button1.Left=label1.Left”。编辑答案:)事实上,这也远不止这些。假设Label1.Left是5,那么每次计时器触发时,它都会加上0+1+2+3+4=10。如果是10,则为0+1+2+3+4+5+6+7+8+9=45。等等……哦,是的,我甚至没想到!:)实际上,他编写的代码会将按钮移动到标签距离的平方,或者某种(+=i在一个for循环中一直到label.Left)啊,是的,比如“button1.Left+=label1.Left”而不是“button1.Left=label1.Left”。编辑答案:)事实上,这也远不止这些。假设Label1.Left是5,那么每次定时器t