共用方式為


Glyph.GetHitTest(Point) 方法

定義

提供點擊測試邏輯。

public:
 abstract System::Windows::Forms::Cursor ^ GetHitTest(System::Drawing::Point p);
public abstract System.Windows.Forms.Cursor GetHitTest (System.Drawing.Point p);
public abstract System.Windows.Forms.Cursor? GetHitTest (System.Drawing.Point p);
abstract member GetHitTest : System.Drawing.Point -> System.Windows.Forms.Cursor
Public MustOverride Function GetHitTest (p As Point) As Cursor

參數

p
Point

要點擊測試的點。

傳回

如果 Cursorp 相關聯,則為 Glyph,否則為 null

範例

下列範例示範如何覆寫 GetHitTest ,以查看點是否在此字元內。 此程式代碼範例是針對 類別提供的較大範例的 BehaviorService 一部分。

public:
    virtual Cursor^ GetHitTest(Point p) override
    {
        // GetHitTest is called to see if the point is
        // within this glyph.  This gives us a chance to decide
        // what cursor to show.  Returning null from here means
        // the mouse pointer is not currently inside of the
        // glyph.  Returning a valid cursor here indicates the
        // pointer is inside the glyph, and also enables our
        // Behavior property as the active behavior.
        if (Bounds.Contains(p))
        {
            return Cursors::Hand;
        }
        return nullptr;
    }
public override Cursor GetHitTest(Point p)
{
    // GetHitTest is called to see if the point is
    // within this glyph.  This gives us a chance to decide
    // what cursor to show.  Returning null from here means
    // the mouse pointer is not currently inside of the glyph.
    // Returning a valid cursor here indicates the pointer is
    // inside the glyph, and also enables our Behavior property
    // as the active behavior.
    if (Bounds.Contains(p))
    {
        return Cursors.Hand;
    }

    return null;
}
Public Overrides Function GetHitTest(ByVal p As Point) As Cursor
    ' GetHitTest is called to see if the point is
    ' within this glyph.  This gives us a chance to decide
    ' what cursor to show.  Returning null from here means
    ' the mouse pointer is not currently inside of the glyph.
    ' Returning a valid cursor here indicates the pointer is
    ' inside the glyph,and also enables our Behavior property
    ' as the active behavior.
    If Bounds.Contains(p) Then
        Return Cursors.Hand
    End If

    Return Nothing

End Function

備註

方法是 GetHitTest 強制 abstract 實作提供點擊測試邏輯的方法 Glyph 。 假設有任一點,如果 Glyph 已決定要與該位置相關,則必須傳回有效的 Cursor。 否則,傳 null 回會導致 BehaviorService 忽略位置。

適用於

另請參閱