Behavior クラス

定義

Behavior によって管理される BehaviorService オブジェクトを表します。Represents the Behavior objects that are managed by a BehaviorService.

public ref class Behavior abstract
public abstract class Behavior
type Behavior = class
Public MustInherit Class Behavior
継承
Behavior

次のコード例は、ユーザーのクリックに応答するBehaviorクラスに基づいて独自のクラスを作成する方法を示しています。The following code example demonstrates how to create your own class based on the Behavior class that responds to user clicks. このコード例は、 BehaviorServiceクラスに対して提供される大規模な例の一部です。This code example is part of a larger example provided for the BehaviorService class.


// 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

注釈

このクラスは、選択、ドラッグ、サイズ変更の動作など、任意の種類のユーザーインターフェイスの動作を開発するように拡張できます。This class can be extended to develop any type of user interface behavior, including selection, drag, and resize behaviors.

詳細については、「動作サービスの概要」を参照してください。For more information, see Behavior Service Overview.

注意

型は、 Glyph型に関連付けられている必要があります。 BehaviorYour Behavior type must be associated with a Glyph type. グリフに依存しない動作はサポートされていません。Glyph-independent behaviors are not supported.

コンストラクター

Behavior()

Behavior クラスの新しいインスタンスを初期化します。Initializes a new instance of the Behavior class.

Behavior(Boolean, BehaviorService)

指定した Behavior を使用して、BehaviorService クラスの新しいインスタンスを初期化します。Initializes a new instance of the Behavior class with the given BehaviorService.

プロパティ

Cursor

この動作に対して表示する必要のあるカーソルを取得します。Gets the cursor that should be displayed for this behavior.

DisableAllCommands

MenuCommand オブジェクトを無効にする必要があるかどうかを示す値を取得します。Gets a value indicating whether MenuCommand objects should be disabled.

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判定します。Determines whether the specified object is equal to the current object.

(継承元 Object)
FindCommand(CommandID)

コマンドを受け取ります。Intercepts commands.

GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(継承元 Object)
OnDragDrop(Glyph, DragEventArgs)

カスタムのドラッグ アンド ドロップ動作を許可します。Permits custom drag-and-drop behavior.

OnDragEnter(Glyph, DragEventArgs)

カスタムの領域内へのドラッグ動作を許可します。Permits custom drag-enter behavior.

OnDragLeave(Glyph, EventArgs)

カスタムの領域外へのドラッグ動作を許可します。Permits custom drag-leave behavior.

OnDragOver(Glyph, DragEventArgs)

カスタムの領域上へのドラッグ動作を許可します。Permits custom drag-over behavior.

OnGiveFeedback(Glyph, GiveFeedbackEventArgs)

カスタムのドラッグ アンド ドロップ フィードバック動作を許可します。Permits custom drag-and-drop feedback behavior.

OnLoseCapture(Glyph, EventArgs)

マウスのキャプチャが失われたときに装飾ウィンドウによって呼び出されます。Called by the adorner window when it loses mouse capture.

OnMouseDoubleClick(Glyph, MouseButtons, Point)

BehaviorService の装飾ウィンドウにダブルクリック メッセージが渡されると呼び出されます。Called when any double-click message enters the adorner window of the BehaviorService.

OnMouseDown(Glyph, MouseButtons, Point)

BehaviorService の装飾ウィンドウにマウスダウン メッセージが渡されると呼び出されます。Called when any mouse-down message enters the adorner window of the BehaviorService.

OnMouseEnter(Glyph)

BehaviorService の装飾ウィンドウにマウスエンター メッセージが渡されると呼び出されます。Called when any mouse-enter message enters the adorner window of the BehaviorService.

OnMouseHover(Glyph, Point)

BehaviorService の装飾ウィンドウにマウスホバー メッセージが渡されると呼び出されます。Called when any mouse-hover message enters the adorner window of the BehaviorService.

OnMouseLeave(Glyph)

BehaviorService の装飾ウィンドウにマウスリーブ メッセージが渡されると呼び出されます。Called when any mouse-leave message enters the adorner window of the BehaviorService.

OnMouseMove(Glyph, MouseButtons, Point)

BehaviorService の装飾ウィンドウにマウス移動メッセージが渡されると呼び出されます。Called when any mouse-move message enters the adorner window of the BehaviorService.

OnMouseUp(Glyph, MouseButtons)

BehaviorService の装飾ウィンドウにマウスアップ メッセージが渡されると呼び出されます。Called when any mouse-up message enters the adorner window of the BehaviorService.

OnQueryContinueDrag(Glyph, QueryContinueDragEventArgs)

装飾ウィンドウから適切な Behavior またはヒット テストされた Glyph にこのドラッグ アンド ドロップ イベントが送信されます。Sends this drag-and-drop event from the adorner window to the appropriate Behavior or hit-tested Glyph.

ToString()

現在のオブジェクトを表す string を返します。Returns a string that represents the current object.

(継承元 Object)

適用対象

こちらもご覧ください