'宣言 Protected Overrides Sub InitAppearance( _ ByRef appearance As Infragistics.Win.AppearanceData, _ ByRef requestedProps As Infragistics.Win.AppearancePropFlags _ )
protected override void InitAppearance( ref Infragistics.Win.AppearanceData appearance, ref Infragistics.Win.AppearancePropFlags requestedProps )
Imports Infragistics.Win Private mouseEnteredElement As Boolean = False Private mouseHoveringOnElement As Boolean = False Protected Overrides Sub InitAppearance(ByRef appearance As AppearanceData, ByRef requestedProps As AppearancePropFlags) MyBase.InitAppearance(appearance, requestedProps) ' マウスが要素の上にあるかどうかに基づいて BackColor を ' 設定します If (Me.mouseHoveringOnElement) Then appearance.BackColor = Color.Green ElseIf (Me.mouseEnteredElement) Then appearance.BackColor = Color.Red Else appearance.BackColor = Color.Transparent End If End Sub Protected Overrides Sub OnMouseEnter() Me.mouseEnteredElement = True ' UIElement の子を (色変更などのために) 再描画する必要がある場合に呼び出します If Not Me.IsDrawing then Me.Invalidate() End If End Sub Protected Overrides Sub OnMouseHover() Me.mouseHoveringOnElement = True ' UIElement の子を位置変更またはサイズ変更する必要がある場合に呼び出します Me.DirtyChildElements() End Sub Protected Overrides Sub OnMouseLeave() Me.mouseHoveringOnElement = False Me.mouseEnteredElement = False If Not Me.IsDrawing then Me.Invalidate() End If End Sub Protected Overrides ReadOnly Property WantsMouseHoverNotification() As Boolean Get Return True End Get End Property
using Infragistics.Win; private bool mouseEnteredElement = false; private bool mouseHoveringOnElement = false; protected override void OnMouseHover() { this.mouseHoveringOnElement = true; // UIElement の子を位置変更またはサイズ変更する必要がある場合に呼び出します this.DirtyChildElements(); } protected override bool WantsMouseHoverNotification { get { return true; } } protected override void OnMouseEnter() { this.mouseEnteredElement = true; // UIElement の子を (色変更などのために) 再描画する必要がある場合に呼び出します if (!this.IsDrawing) this.Invalidate(); } protected override void OnMouseLeave() { this.mouseHoveringOnElement = false; this.mouseEnteredElement = false; // UIElement の子を (色変更などのために) 再描画する必要がある場合に呼び出します if (!this.IsDrawing) this.Invalidate(); } protected override void InitAppearance(ref AppearanceData appearance, ref AppearancePropFlags requestedProps) { base.InitAppearance(ref appearance, ref requestedProps); // マウスが要素の上にあるかどうかに基づいて BackColor を // 設定します if(this.mouseHoveringOnElement) appearance.BackColor = Color.Green; else if(this.mouseEnteredElement) appearance.BackColor = Color.Red; else appearance.BackColor = Color.Transparent ; }