Glyph Sınıf

Tanım

tarafından yönetilen Adornertek bir kullanıcı arabirimi (UI) varlığını temsil eder.

C#
public abstract class Glyph
Devralma
Glyph
Türetilmiş

Örnekler

Aşağıdaki örnekte, kendisiyle ilişkilendirilmiş kendi Glyph tabanlı sınıfınızı Behavior nasıl oluşturacağınız gösterilmektedir. Bu kod örneği, sınıfı için BehaviorService sağlanan daha büyük bir örneğin parçasıdır.

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.
        }
    }
}

Açıklamalar

Tek amacı Glyph boyamak ve test etmektir. öğesinin Glyph donatıcı pencere denetiminde işlendiğinden, bir pencere tutamacına BehaviorService(HWND) sahip değildir. Her Glyph biri Behavior onunla ilişkili olabilir. Başarılı bir isabet sınaması Glyph , 'nin davranış yığınına yeni veya farklı Behavior bir gönderme fırsatına BehaviorServicesahiptir.

Daha fazla bilgi için bkz . Davranış Hizmetine Genel Bakış.

Oluşturucular

Glyph(Behavior)

Glyph sınıfının yeni bir örneğini başlatır.

Özellikler

Behavior

Behavior ile ilişkili Glyph öğesini alır.

Bounds

sınırlarını Glyphalır.

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetHitTest(Point)

İsabet testi mantığı sağlar.

GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
Paint(PaintEventArgs)

Boya mantığı sağlar.

SetBehavior(Behavior)

ile ilişkili öğesini BehaviorGlyphdeğiştirir.

ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ürün Sürümler
.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

Ayrıca bkz.