RichTextBox.AllowDrop プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > RichTextBox.AllowDrop プロパティの意味・解説 

RichTextBox.AllowDrop プロパティ

コントロールドラッグ アンド ドロップ操作実行できるかどうかを示す値を取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

使用例使用例

RichTextBox コントロールドロップする項目が格納されている ListBox コントロール使用してドラッグ アンド ドロップ操作実行する方法次のコード例示しますフォームコンストラクタは、AllowDrop プロパティtrue設定してRichTextBoxドラッグ アンド ドロップ操作実行できるようにします。この例では、ListBox の MouseDown イベント使用し、DoDragDrop メソッド呼び出すことによってドラッグ操作開始してます。この例では、RichTextBoxドラッグされている項目が有効なデータ型かどうか判別するために DragEnter イベント使用してます。DragDrop イベントでは、ドラッグされた項目を実際に RichTextBox コントロールの、RichTextBox 内の現在のカーソル位置ドロップます。この例では、DragDrop イベントおよび DragEnter イベントが、この例で定義されているイベント ハンドラ関連付けられている必要があります

Public Sub New()
   MyBase.New()

   'This call is required by the Windows Form Designer.
   InitializeComponent()

   richTextBox1.AllowDrop = True

End Sub

Private Sub listBox1_MouseDown(ByVal
 sender As Object, ByVal
 e As System.Windows.Forms.MouseEventArgs) Handles listBox1.MouseDown
   ' Determines which item was selected.
   Dim lb As ListBox = CType(sender, ListBox)
   Dim pt As New Point(e.X,
 e.Y)
   'Retrieve the item at the specified location within the ListBox.
   Dim index As Integer
 = lb.IndexFromPoint(pt)

   ' Starts a drag-and-drop operation.
   If index >= 0 Then
      ' Retrieve the selected item text to drag into the RichTextBox.
      lb.DoDragDrop(lb.Items(index).ToString(), DragDropEffects.Copy)
   End If
End Sub 'listBox1_MouseDown


Private Sub richTextBox1_DragEnter(ByVal
 sender As Object, ByVal
 e As DragEventArgs) Handles richTextBox1.DragEnter
   ' If the data is text, copy the data to the RichTextBox control.
   If e.Data.GetDataPresent("Text")
 Then
      e.Effect = DragDropEffects.Copy
   End If
End Sub 'richTextBox1_DragEnter

Private Sub richTextBox1_DragDrop(ByVal
 sender As Object, ByVal
 e As DragEventArgs) Handles richTextBox1.DragDrop
   ' Paste the text into the RichTextBox where at selection location.
   richTextBox1.SelectedText = e.Data.GetData("System.String",
 True).ToString()
End Sub 'richTextBox1_DragDrop

public Form1()
{
   InitializeComponent();
   // Sets the control to allow drops, and then adds the necessary event
 handlers.
   this.richTextBox1.AllowDrop = true;
}
 
private void listBox1_MouseDown(object sender,
 System.Windows.Forms.MouseEventArgs e)
{
   // Determines which item was selected.
   ListBox lb =( (ListBox)sender);
   Point pt = new Point(e.X,e.Y);
   //Retrieve the item at the specified location within the ListBox.
   int index = lb.IndexFromPoint(pt);

   // Starts a drag-and-drop operation.
   if(index>=0) 
   {
      // Retrieve the selected item text to drag into the RichTextBox.
      lb.DoDragDrop(lb.Items[index].ToString(), DragDropEffects.Copy);
   }
}

private void richTextBox1_DragEnter(object
 sender, DragEventArgs e)
{
   // If the data is text, copy the data to the RichTextBox control.
   if(e.Data.GetDataPresent("Text"))
      e.Effect = DragDropEffects.Copy;
}

private void richTextBox1_DragDrop(object sender,
 DragEventArgs e) 
{
   // Paste the text into the RichTextBox where at selection location.
   richTextBox1.SelectedText =  e.Data.GetData("System.String", true).ToString();
}

public:
   Form1()
   {
      InitializeComponent();
      
      // Sets the control to allow drops, and then adds the necessary event
 handlers.
      this->richTextBox1->AllowDrop = true;
   }

private:
   void listBox1_MouseDown( Object^ sender, System::Windows::Forms::MouseEventArgs^
 e )
   {
      // Determines which item was selected.
      ListBox^ lb = (dynamic_cast<ListBox^>(sender));
      Point pt = Point(e->X,e->Y);

      //Retrieve the item at the specified location within the ListBox.
      int index = lb->IndexFromPoint( pt );

      // Starts a drag-and-drop operation.
      if ( index >= 0 )
      {
         // Retrieve the selected item text to drag into the RichTextBox.
         lb->DoDragDrop( lb->Items[ index ]->ToString(), DragDropEffects::Copy
 );
      }
   }

   void richTextBox1_DragEnter( Object^ /*sender*/, DragEventArgs^
 e )
   {
      // If the data is text, copy the data to the RichTextBox control.
      if ( e->Data->GetDataPresent( "Text" ) )
            e->Effect = DragDropEffects::Copy;
   }

   void richTextBox1_DragDrop( Object^ /*sender*/, DragEventArgs^
 e )
   {
      // Paste the text into the RichTextBox where at selection location.
      richTextBox1->SelectedText = e->Data->GetData( "System.String",
 true )->ToString();
   }
public Form1()
{
    InitializeComponent();
    //Sets the control to allow drops, and then adds the necessary 
    //event handlers.
    this.richTextBox1.set_AllowDrop(true);
} //Form1

private void listBox1_MouseDown(Object sender,
 System.Windows.Forms.
    MouseEventArgs e)
{
    //Determines which item was selected.
    ListBox lb =(ListBox)sender;
    Point pt = new Point(e.get_X(), e.get_Y());
    //Retrieve the item at the specified location within the ListBox.
    int index = lb.IndexFromPoint(pt);
    //Starts a drag-and-drop operation.
    if (index >= 0) {
        //Retrieve the selected item text to drag into the RichTextBox.
        lb.DoDragDrop(lb.get_Items().get_Item(index).ToString(), 
            DragDropEffects.Copy);
    }
} //listBox1_MouseDown

private void richTextBox1_DragEnter(Object
 sender, DragEventArgs e)
{
    // If the data is text, copy the data to the RichTextBox control.
    if (e.get_Data().GetDataPresent("Text")) {
        e.set_Effect(DragDropEffects.Copy);
    }
} //richTextBox1_DragEnter

private void richTextBox1_DragDrop(Object sender,
 DragEventArgs e)
{
    // Paste the text into the RichTextBox where at selection location.
    richTextBox1.set_SelectedText(e.get_Data().GetData("System.String",
 true).
        ToString());
} //richTextBox1_DragDrop
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

RichTextBox.AllowDrop プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



RichTextBox.AllowDrop プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS