拖动后的动画效果

flurrying 2009-03-04 03:41:12
假设窗体中有Label控件

实现的效果:
拖动Label控件,
鼠标放开以后。
Label控件出现动画效果 ,
Label控件回到拖动前的位置 .
...全文
91 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
flurrying 2009-03-04
  • 打赏
  • 举报
回复
就是这个效果
不过控件的画面变了!
  • 打赏
  • 举报
回复
1楼的大侠 能不能解释下啊?
北京的雾霾天 2009-03-04
  • 打赏
  • 举报
回复
不知道这样算不算附合要求:


private Point m_OldPoint;
private Point m_OldLocation;
private void label1_MouseDown(object sender, MouseEventArgs e)
{
Control ctr = sender as Control;
this.m_OldPoint = this.PointToScreen(e.Location);
m_OldLocation = ctr.Location;
}

private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Control ctr = sender as Control;
Point nPoint = this.PointToScreen(e.Location);
Point n = ctr.Location;
n.Offset(nPoint.X - this.m_OldPoint.X, nPoint.Y - this.m_OldPoint.Y);
ctr.Location = n;
}
}

private void label1_MouseUp(object sender, MouseEventArgs e)
{
Control ctr = sender as Control;
Point p = ctr.Location;
Point op = m_OldLocation;

if (p.X != op.X && p.Y!=op.Y)
{
float k = (p.Y - op.Y) / ((p.X - op.X) * 1.0f);

if (p.X < op.X)
{
for (int x = p.X; x < op.X; x++)
{
float y = k * (x - p.X) + p.Y;
ctr.Location = new Point(x, (int)y);
}
}
else
{
for (int x = p.X; x > op.X; x--)
{
float y = k * (x - p.X) + p.Y;
ctr.Location = new Point(x, (int)y);
}
}
}
}

111,126

社区成员

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

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

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