关于鼠标划过控件放大的问题

sardineany 2010-06-21 01:30:08
我现在要实现的功能是鼠标划过一个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从他的中心开始放大和缩小。。本人是新手,希望各位高手不吝赐教。。小弟这里谢过了
...全文
195 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiandi0074 2010-06-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 cejay 的回复:]

必须从左上角放大吧,你可以这样实现:按钮高和宽增的时候按钮相对与窗体的位置的X,Y轴让他减少相应的像素。按钮高和宽恢复正常的时候,把按钮相对与窗体的位置还原回去就是了
[/Quote]
不错
sardineany 2010-06-21
  • 打赏
  • 举报
回复
解决了,谢谢大家
xiemeilin 2010-06-21
  • 打赏
  • 举报
回复
那如果连里面的字体也跟着放大缩小呢?
assky124 2010-06-21
  • 打赏
  • 举报
回复

//没有渐变效果意思下
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;
}


大飞飞虫 2010-06-21
  • 打赏
  • 举报
回复
用WPF把,折腾的
sardineany 2010-06-21
  • 打赏
  • 举报
回复
不是我要的效果,不过还是谢谢你
cejay 2010-06-21
  • 打赏
  • 举报
回复


private void timer1_Tick(object sender, EventArgs e)
{
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;
}


你试试行不,我不也不知道效果
sardineany 2010-06-21
  • 打赏
  • 举报
回复
代码在上面。。怎么修改。。谢谢
cejay 2010-06-21
  • 打赏
  • 举报
回复
必须从左上角放大吧,你可以这样实现:按钮高和宽增的时候按钮相对与窗体的位置的X,Y轴让他减少相应的像素。按钮高和宽恢复正常的时候,把按钮相对与窗体的位置还原回去就是了
sardineany 2010-06-21
  • 打赏
  • 举报
回复
能否具体点,谢谢。。。
showlin 2010-06-21
  • 打赏
  • 举报
回复
设置Size时,同时设置Location

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧