RichTextBox.AllowDrop プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As RichTextBox Dim value As Boolean value = instance.AllowDrop instance.AllowDrop = value
/** @property */ public boolean get_AllowDrop () /** @property */ public void set_AllowDrop (boolean value)
public override function get AllowDrop () : boolean public override function set AllowDrop (value : boolean)
コントロールでドラッグ アンド ドロップを実行できる場合は true。それ以外の場合は false。

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

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


Weblioに収録されているすべての辞書からRichTextBox.AllowDrop プロパティを検索する場合は、下記のリンクをクリックしてください。

- RichTextBox.AllowDrop プロパティのページへのリンク