用户绘制的控件:MSN聊天窗口

时间:2010-03-14 23:20:23

标签: c# .net winforms

我想知道着名的MSN聊天客户对话窗口!我敢肯定必须有很多不同的方面,但我想专注于那些小滑动窗格。例如,显示对话中人物的图片。当您单击折叠按钮时,图片会消失,面板会优雅地滑入,当您再次单击它以展开时,它会滑出并且图片会平滑地淡入。

如何在具有类似行为的WinForms中自定义绘制控件?

1 个答案:

答案 0 :(得分: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

}

对于图片,类似但使用translucent images,你可能想要为它们制作一个具有透明背景颜色的新控件,以及你想要绘制的东西。

然后,您可以将此控件放入其中一个LayoutPanel控件中,以便在表单中移动其他控件以匹配宽度。

相关问题