簡體   English   中英

用戶繪制的控件:MSN聊天窗口

[英]User Drawn Controls: the MSN chat window

我想知道着名的MSN聊天客戶對話窗口! 我敢肯定必須有很多不同的方面,但我想專注於那些小滑動窗格。 例如,顯示對話中人物的圖片。 當您單擊折疊按鈕時,圖片會消失,面板會優雅地滑入,當您再次單擊它以展開時,它會滑出並且圖片會平滑地淡入。

如何在具有類似行為的WinForms中自定義繪制控件?

這應該可以讓您了解如何為您的寬度設置動畫。

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

}

而對於圖片,類似但使用半透明圖像的東西 ,你可能想要為它們制作一個具有透明背景顏色的新控件,以及你想要如何繪制東西。

然后,您可以將此控件放入其中一個LayoutPanel控件中,以在窗體中移動其他控件以匹配寬度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM