我想知道着名的MSN聊天客户对话窗口!我敢肯定必须有很多不同的方面,但我想专注于那些小滑动窗格.例如,显示对话中人物的图片.当您单击折叠按钮时,图片会消失,面板会优雅地滑入,当您再次单击它以展开时,它会滑出并且图片会平滑地淡入.
如何在具有类似行为的WinForms中自定义绘制控件?
小智 2
这应该让您了解如何为宽度设置动画。
int _collapsedWidth;
int _fullWidth;
float _speed;
float _acurateWidth;
System.Diagnostics.Stopwatch _stopwatch = new Stopwatch ();
int _animationDirection;
AnimatedControl (){
Application.Idle += ApplicationIdle;
}
void Expand (){
_animationDirection = 1;
_stopwatch.Start();
}
void ApplicationIdle (object sender, EventArgs e){
if (_animation.Direction == 0)
return;
float delta = _stopwatch.Elapsed.TotalMilliseconds * _speed;
_acurateWidth += delta;
if (_acurateWidth < _collapsedWidth)
{
_animationDirection = 0;
_acurateWidth = _collapsedWidth;
_stopwatch.Stop();
}
else if (_acurateWidth > _fullWidth)
{
_animationDirection = 0;
_acurateWidth = _fullWidth;
_stopwatch.Stop();
}
_stopwatch.Reset();
this.Width = (int)System.Math.Round(_acurateWidth , MidpointRounding.AwayFromZero);
this.Invalidate (); // May not need this
}
Run Code Online (Sandbox Code Playgroud)
对于图片,类似但使用半透明图像,您可能还想为它们制作一个具有透明背景颜色的新控件,具体取决于您想要如何绘制事物。
然后,您可以将此控件放入其中一个控件中LayoutPanel,以在窗体中移动其他控件以匹配宽度。
| 归档时间: |
|
| 查看次数: |
223 次 |
| 最近记录: |