Glyph 類別

定義

代表由 Adorner 管理的單一使用者介面 (UI) 實體 (Entity)。

C#
public abstract class Glyph
繼承
Glyph
衍生

範例

下列範例示範如何建立您自己的 Glyph 型類別,並與其 Behavior 相關聯。 此程式代碼範例是針對 類別提供的較大範例的 BehaviorService 一部分。

C#
class MyGlyph : Glyph
{
    Control control;
    BehaviorService behaviorSvc;

    public MyGlyph(BehaviorService behaviorSvc, Control control) : 
        base(new MyBehavior())
    {
        this.behaviorSvc = behaviorSvc;
        this.control = control;
    }

    public override Rectangle Bounds
    {
        get
        {
            // Create a glyph that is 10x10 and sitting
            // in the middle of the control.  Glyph coordinates
            // are in adorner window coordinates, so we must map
            // using the behavior service.
            Point edge = behaviorSvc.ControlToAdornerWindow(control);
            Size size = control.Size;
            Point center = new Point(edge.X + (size.Width / 2), 
                edge.Y + (size.Height / 2));

            Rectangle bounds = new Rectangle(
                center.X - 5,
                center.Y - 5,
                10,
                10);

            return bounds;
        }
    }

    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 override void Paint(PaintEventArgs pe)
    {
        // Draw our glyph. It is simply a blue ellipse.
        pe.Graphics.FillEllipse(Brushes.Blue, Bounds);
    }

    // By providing our own behavior we can do something interesting
    // when the user clicks or manipulates our glyph.
    class MyBehavior : Behavior
    {
        public override bool OnMouseUp(Glyph g, MouseButtons button)
        {
            MessageBox.Show("Hey, you clicked the mouse here");
            return true; // indicating we processed this event.
        }
    }
}

備註

的唯一 Glyph 用途是繪製和點擊測試。 Glyph沒有視窗句柄 (HWND) ,因為它會在 的裝飾項視窗控件BehaviorService上呈現。 每個 Glyph 都可以有與其 Behavior 相關聯的 。 成功的點擊測試 Glyph 有機會將新的或不同的 Behavior 推送至 的行為 BehaviorService堆疊。

如需詳細資訊,請參閱 行為服務概觀

建構函式

Glyph(Behavior)

初始化 Glyph 類別的新執行個體。

屬性

Behavior

取得與 Behavior 相關聯的 Glyph

Bounds

取得 Glyph 的界限。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetHitTest(Point)

提供點擊測試邏輯。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
Paint(PaintEventArgs)

提供繪製邏輯。

SetBehavior(Behavior)

變更與 Behavior 相關聯的 Glyph

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱