方法 : RichTextBox の MouseUp イベントと MouseDown イベントを処理する

更新 : 2007 年 11 月

RichTextBox での MouseUp および MouseDown を処理する例を次に示します。

RichTextBox には、バブルMouseUp および MouseDown イベントのための処理が組み込まれています。そのため、RichTextBox からの MouseUp イベントまたは MouseDown イベントをリッスンするカスタム イベント ハンドラは呼び出されません。これらのイベントに応答する必要がある場合は、代わりにトンネルPreviewMouseUp イベントおよび PreviewMouseDown イベントをリッスンします。

使用例

PreviewMouseUp 属性および PreviewMouseDown 属性を使用して、これらのイベントのハンドラ デリゲートを指定する方法を次の Extensible Application Markup Language (XAML) の例に示します。

<RichTextBox 
  PreviewMouseUp="MouseUpHandler"
  PreviewMouseDown="MouseDownHandler"
/>

プログラムによってイベント リスナを追加する方法を次の例に示します。

RichTextBox richTextBox = new RichTextBox();
richTextBox.PreviewMouseUp += MouseUpHandler;
richTextBox.PreviewMouseDown += MouseDownHandler;
// Note: Event listeners can also be added using the AddHandler
// method.

前の例で指定されたデリゲートに対応する空のイベント ハンドラ メソッドを次の例に示します。

void MouseUpHandler(Object sender, RoutedEventArgs args)
{
    // This method is called whenever the PreviewMouseUp event fires.
}

void MouseDownHandler(Object sender, RoutedEventArgs args)
{
    // This method is called whenever the PreviewMouseDown event fires.
}

参照

概念

RichTextBox の概要

TextBox の概要