2012-02-07 44 views
3

我創建了一個自定義面板控制如下:如何淡入和淡出的自定義面板控制在vb.net

Namespace CustomPanelControl 
Public Class CustomPanel 
    Inherits Panel 

    Public Sub New() 
     MyBase.New() 
    End Sub 
    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams 
     Get 
      Dim cp As CreateParams = MyBase.CreateParams 
      cp.ExStyle = &H20 
      Return cp 
     End Get 
    End Property 

    Protected Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs) 
     'do nothing here 
    End Sub 

    Public Overrides Sub Refresh() 
     Parent.Invalidate(New Rectangle(Me.Location, Me.Size), True) 
    End Sub 

    Protected Sub InvalidateEx() 
     If Parent Is Nothing Then 
      Return 
     End If 
     Dim rc As New Rectangle(Me.Location, Me.Size) 
     Parent.Invalidate(rc, True) 
    End Sub 
End Class 
End Namespace 

現在我需要使用它,並使它淡入和淡出。這是一個包含典型的播放,停止,FF,REW控制媒體播放器的面板。就像Windows Player或VLC一樣,我希望包含控件的面板在鼠標離開時淡出,並在鼠標輸入時淡入。

我該怎麼做? TIA!

回答

0

Winforms沒有任何機制。表單具有不透明性,但控件不具有。

您可以嘗試採取的控制快照使用DrawToBitmap(...),然後放置位圖一個無國界的作弊,在控制區focusless形式,然後從那裏消失的不透明度值。

但是使用WinForms的任何解決方案都會變得有點詭異。這裏的標準答案是考慮WPF或重新考慮你的動畫需求。