我现在要实现的功能是鼠标划过一个butto 这个Button放大,然后离开的时候,这个button又恢复原貌。
我的实现代码是:
private void timer1_Tick(object sender, EventArgs e)
{
if (simpleButton1.Height < 50 )
{
simpleButton1.Height += 3;
}
if (simpleButton1.Width < 100)
{
simpleButton1.Width += 6;
simpleButton1.Size = "1,1";
} }
private void simpleButton1_MouseEnter(object sender, EventArgs e)
{
timer1.Enabled = true;
timer2.Enabled = false;
} private void timer2_Tick(object sender, EventArgs e)
{
if ( simpleButton1.Width > 46)
{
simpleButton1.Width -= 6;
}
if (simpleButton1.Height > 23)
{
simpleButton1.Height -= 3;
}
} private void simpleButton1_MouseLeave(object sender, EventArgs e)
{
timer1.Enabled = false;
timer2.Enabled = true;
}这样有一个问题就是,他的改变是将左上角的一点固定然后进行放大和缩小,看着很僵硬,我想知道,可不可以让这个button从他的中心开始放大和缩小。。本人是新手,希望各位高手不吝赐教。。小弟这里谢过了
我的实现代码是:
private void timer1_Tick(object sender, EventArgs e)
{
if (simpleButton1.Height < 50 )
{
simpleButton1.Height += 3;
}
if (simpleButton1.Width < 100)
{
simpleButton1.Width += 6;
simpleButton1.Size = "1,1";
} }
private void simpleButton1_MouseEnter(object sender, EventArgs e)
{
timer1.Enabled = true;
timer2.Enabled = false;
} private void timer2_Tick(object sender, EventArgs e)
{
if ( simpleButton1.Width > 46)
{
simpleButton1.Width -= 6;
}
if (simpleButton1.Height > 23)
{
simpleButton1.Height -= 3;
}
} private void simpleButton1_MouseLeave(object sender, EventArgs e)
{
timer1.Enabled = false;
timer2.Enabled = true;
}这样有一个问题就是,他的改变是将左上角的一点固定然后进行放大和缩小,看着很僵硬,我想知道,可不可以让这个button从他的中心开始放大和缩小。。本人是新手,希望各位高手不吝赐教。。小弟这里谢过了
{
if (simpleButton1.Height < 50 )
{
simpleButton1.Height += 3;
simpleButton1.Location = new System.Drawing.Point(simpleButton1.Location.X - 3, simpleButton1.Location.Y);
}
if (simpleButton1.Width < 100)
{
simpleButton1.Width += 6;
simpleButton1.Location = new System.Drawing.Point(simpleButton1.Location.X, simpleButton1.Location.Y-6);
} }
private void simpleButton1_MouseEnter(object sender, EventArgs e)
{
timer1.Enabled = true;
timer2.Enabled = false;
} private void timer2_Tick(object sender, EventArgs e)
{
if ( simpleButton1.Width > 46)
{
simpleButton1.Width -= 6;
simpleButton1.Location = new System.Drawing.Point(simpleButton1.Location.X, simpleButton1.Location.Y+ 6);
}
if (simpleButton1.Height > 23)
{
simpleButton1.Height -= 3;
simpleButton1.Location = new System.Drawing.Point(simpleButton1.Location.X + 3, simpleButton1.Location.Y);
}
} private void simpleButton1_MouseLeave(object sender, EventArgs e)
{
timer1.Enabled = false;
timer2.Enabled = true;
}
你试试行不,我不也不知道效果
//没有渐变效果意思下
private int _iStep; //步长
private void simpleButton1_MouseEnter(object sender, EventArgs e)
{
simpleButton1.Top -= _iStep;
simpleButton1.Left -= _iStep;
simpleButton1.Width += 2*_iStep;
simpleButton1.Height += 2*_iStep;
} private void simpleButton1_MouseLeave(object sender, EventArgs e)
{
simpleButton1.Top += _iStep;
simpleButton1.Left += _iStep;
simpleButton1.Width -= 2*_iStep;
simpleButton1.Height -= 2*_iStep;
}