我有目前2個圖像之間的切換正常和鼠標狀態上的類,但我想補充的是,2IE 9等Winforms中按鈕熱跟蹤
之間切換的微妙的動畫是否有任何(簡單)的方式來讓一個按鈕具有動畫效果,例如IE 9瀏覽器中的按鈕。
編輯:
這裏是我通過joe_coolish
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(_normalImage, 0, 0);
ColorMatrix matrix = new ColorMatrix();
matrix.Matrix33 = _opacity;
ImageAttributes attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
e.Graphics.DrawImage(_hotImage, this.DisplayRectangle, 0, 0,
this.DisplayRectangle.Width, this.DisplayRectangle.Height, GraphicsUnit.Pixel, attributes);
if (_opacity < 1 && _over)
{
_opacity += 0.02f;
_opacity = Math.Min(1, _opacity);
this.Invalidate();
}
if (_opacity > 0 && !_over)
{
_opacity -= 0.02f;
_opacity = Math.Max(0, _opacity);
this.Invalidate();
}
}
使用的OnPaint過載感謝答案最終溶液我結束了一種能夠防止不透明度從上述1或低於設定0,否則我最終會遇到一些奇怪的行爲。
注意:確保控制是雙緩衝或否則閃爍不好也很重要。
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
改變焦點或鼠標上的圖像是否有意義?我錯過了什麼嗎? – 2011-12-29 03:26:48
我希望控件在鼠標懸停時更改圖像,並在鼠標離開時恢復正常。我的問題不是關於狀態如何/何時改變,而是關於如何在狀態發生變化時對其進行動畫處理。 – ChandlerPelhams 2011-12-29 03:51:08
我的解決方案適合您嗎? – 2011-12-29 15:28:52