Glyph 类

定义

表示一个由 Adorner 管理的用户界面 (UI) 实体。

C#
public abstract class Glyph
继承
Glyph
派生

示例

下面的示例演示如何创建与它关联的基于自己的 GlyphBehavior 。 此代码示例是为 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

另请参阅