Behavior 클래스

정의

Behavior에서 관리하는 BehaviorService 개체를 나타냅니다.

public ref class Behavior abstract
public abstract class Behavior
type Behavior = class
Public MustInherit Class Behavior
상속
Behavior

예제

다음 코드 예제에서는 사용자 클릭에 응답 하는 클래스에 따라 사용자 고유의 Behavior 클래스를 만드는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 BehaviorService 클래스입니다.


// By providing our own behavior we can do something
// interesting when the user clicks or manipulates our glyph.
public  ref class DemoBehavior : public Behavior
{
public:
    bool OnMouseUp(Glyph^ g, MouseButtons^ button)
    {
        MessageBox::Show("Hey, you clicked the mouse here");

        // indicating we processed this event.
        return true;
    }
};

public ref class DemoGlyph : public Glyph
{
    Control^ control;
    BehaviorService^ behavior;

public:
    DemoGlyph(BehaviorService^ behavior, Control^ control):
      Glyph(gcnew BehaviorServiceSample::DemoBehavior)
      {
          this->behavior = behavior;
          this->control = control;
      }

public:
    virtual property Rectangle Bounds
    {
        Rectangle get() override
        {
            // 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 = behavior->ControlToAdornerWindow(control);
            Size size = control->Size;
            Point center = Point(edge.X + (size.Width / 2),
                edge.Y + (size.Height / 2));

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

            return bounds;
        }
    }

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:
    virtual void Paint(PaintEventArgs^ pe) override
    {
        // Draw our glyph.  Our's is simple:  a blue ellipse.
        pe->Graphics->FillEllipse(Brushes::Blue, Bounds);
    }
};
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.
        }
    }
}
Class MyGlyph
    Inherits Glyph
    Private control As Control
    Private behaviorSvc As _
        System.Windows.Forms.Design.Behavior.BehaviorService

    Public Sub New(ByVal behaviorSvc As _
        System.Windows.Forms.Design.Behavior.BehaviorService, _
        ByVal control As Control)

        MyBase.New(New MyBehavior())
        Me.behaviorSvc = behaviorSvc
        Me.control = control
    End Sub

    Public Overrides ReadOnly Property Bounds() As Rectangle
        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.
            Dim edge As Point = behaviorSvc.ControlToAdornerWindow(control)
            Dim size As Size = control.Size
            Dim center As New Point(edge.X + size.Width / 2, edge.Y + _
                size.Height / 2)

            Dim bounds1 As New Rectangle(center.X - 5, center.Y - 5, 10, 10)

            Return bounds1
        End Get
    End Property

    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


    Public Overrides Sub Paint(ByVal pe As PaintEventArgs)
        ' Draw our glyph.  It is simply a blue ellipse.
        pe.Graphics.FillEllipse(Brushes.Blue, Bounds)

    End Sub

    ' By providing our own behavior we can do something interesting
    ' when the user clicks or manipulates our glyph.

    Class MyBehavior
        Inherits System.Windows.Forms.Design.Behavior.Behavior

        Public Overrides Function OnMouseUp(ByVal g As Glyph, _
            ByVal button As MouseButtons) As Boolean
            MessageBox.Show("Hey, you clicked the mouse here")
            Return True
            ' indicating we processed this event.
        End Function 'OnMouseUp
    End Class

End Class

설명

이 클래스를 확장하여 선택, 끌기 및 크기 조정 동작을 비롯한 모든 유형의 사용자 인터페이스 동작을 개발할 수 있습니다.

자세한 내용은 동작 서비스 개요를 참조하세요.

참고

형식 Behavior 은 형식과 Glyph 연결되어야 합니다. 문자 모양 독립적 동작은 지원되지 않습니다.

생성자

Behavior()

Behavior 클래스의 새 인스턴스를 초기화합니다.

Behavior(Boolean, BehaviorService)

주어진 Behavior을 사용하여 BehaviorService 클래스의 새 인스턴스를 초기화합니다.

속성

Cursor

이 동작에 대해 표시할 커서를 가져옵니다.

DisableAllCommands

MenuCommand 개체를 비활성화해야 하는지 여부를 나타내는 값을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
FindCommand(CommandID)

명령을 차단합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnDragDrop(Glyph, DragEventArgs)

끌어서 놓기 동작을 사용자 지정할 수 있습니다.

OnDragEnter(Glyph, DragEventArgs)

범위 안으로 끌기 동작을 사용자 지정할 수 있습니다.

OnDragLeave(Glyph, EventArgs)

범위 밖으로 끌기 동작을 사용자 지정할 수 있습니다.

OnDragOver(Glyph, DragEventArgs)

범위 위로 끌기 동작을 사용자 지정할 수 있습니다.

OnGiveFeedback(Glyph, GiveFeedbackEventArgs)

끌어서 놓기 피드백 동작을 사용자 지정할 수 있습니다.

OnLoseCapture(Glyph, EventArgs)

표시기 창에서 마우스 캡처가 손실될 때 호출됩니다.

OnMouseDoubleClick(Glyph, MouseButtons, Point)

BehaviorService의 표시기 창에 두 번 클릭 메시지가 전달될 때 호출됩니다.

OnMouseDown(Glyph, MouseButtons, Point)

BehaviorService의 표시기 창에 마우스 클릭 메시지가 전달될 때 호출됩니다.

OnMouseEnter(Glyph)

BehaviorService의 표시기 창에 마우스 이동 메시지가 전달될 때 호출됩니다.

OnMouseHover(Glyph, Point)

BehaviorService의 표시기 창에 위로 마우스 호버 메시지가 전달될 때 호출됩니다.

OnMouseLeave(Glyph)

BehaviorService의 표시기 창에 범위 밖으로 마우스 이동 메시지가 전달될 때 호출됩니다.

OnMouseMove(Glyph, MouseButtons, Point)

BehaviorService의 표시기 창에 마우스 이동 메시지가 전달될 때 호출됩니다.

OnMouseUp(Glyph, MouseButtons)

BehaviorService의 표시기 창에 마우스 놓기 메시지가 전달될 때 호출됩니다.

OnQueryContinueDrag(Glyph, QueryContinueDragEventArgs)

표시기 창에서 적절한 Behavior 또는 적중 테스트가 수행된 Glyph에 이 끌어서 놓기 이벤트를 전달합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보