Behavior クラス
アセンブリ: System.Design (system.design.dll 内)



ユーザーのクリック操作に応答する Behavior クラスに基づいて独自のクラスを作成する方法を次のコード例に示します。このコード例は、BehaviorService クラスのトピックで取り上げているコード例の一部分です。
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
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. } } }

System.Windows.Forms.Design.Behavior.Behavior


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Behavior コンストラクタ ()
アセンブリ: System.Design (system.design.dll 内)


Behavior クラスの新しいインスタンスを初期化する方法を次のコード例に示します。このコード例は、BehaviorService クラスのトピックで取り上げているコード例の一部分です。


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Behavior コンストラクタ (Boolean, BehaviorService)
アセンブリ: System.Design (system.design.dll 内)

Dim callParentBehavior As Boolean Dim behaviorService As BehaviorService Dim instance As New Behavior(callParentBehavior, behaviorService)
- behaviorService
使用する BehaviorService。


親動作は、BehaviorService が管理する動作スタック上の次の動作です。callParentBehavior パラメータが true の場合は、behaviorService パラメータを null 参照 (Visual Basic では Nothing) に設定しないでください。
callParentBehavior は、Behavior 基本クラスで親動作を呼び出し、BehaviorService で正しい親動作を選択する必要があるかどうかを示します。


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Behavior コンストラクタ

名前 | 説明 |
---|---|
Behavior () | Behavior クラスの新しいインスタンスを初期化します。 |
Behavior (Boolean, BehaviorService) | 指定した BehaviorService を使用して、Behavior クラスの新しいインスタンスを初期化します。 |

Behavior プロパティ

名前 | 説明 | |
---|---|---|
![]() | Cursor | この動作に対して表示する必要のあるカーソルを取得します。 |
![]() | DisableAllCommands | MenuCommand オブジェクトを無効にする必要があるかどうかを示す値を取得します。 |

Behavior メソッド


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

Behavior メンバ
BehaviorService によって管理される Behavior オブジェクトを表します。
Behavior データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Cursor | この動作に対して表示する必要のあるカーソルを取得します。 |
![]() | DisableAllCommands | MenuCommand オブジェクトを無効にする必要があるかどうかを示す値を取得します。 |


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からBehaviorを検索する場合は、下記のリンクをクリックしてください。

- Behaviorのページへのリンク