RichTextBox.DragDrop 事件  [C#]该成员支持 .NET Framework 结构,因此不适用于直接从代码中使用。[C#]
public new event DragEventHandler DragDrop;

解决方案 »

  1.   

    richtextbox不支持拖放事件。因此在设计器里看不到那个事件。
      

  2.   

    以下示例阐释如何在拖放操作的源和目标之间传递 DragEventArgs。在此示例中,ListBox 控件是数据的源,而 RichTextBox 控件是目标。此示例假定 ListBox 控件已经用有效的文件名列表进行了填充。当用户将显示的某个文件名从 ListBox 控件拖到 RichTextBox 控件上时,将打开该文件名所引用的文件。[Visual Basic, C#, C++] 该操作在 ListBox 控件的 MouseDown 事件中启动。在 DragEnter 事件处理程序中,该示例使用 GetDataPresent 方法验证数据的格式是否为 RichTextBox 控件能够显示的格式,然后设置 DragDropEffects 属性以指定数据应从源控件复制到目标控件。最后,RichTextBox 控件的 DragDrop 事件处理程序使用 GetData 方法检索要打开的文件名。[Visual Basic] 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       ' Sets the AllowDrop property so that data can be dragged onto the control.
       RichTextBox1.AllowDrop = True   ' Add code here to populate the ListBox1 with paths to text files.End SubPrivate Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.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
    Private Overloads Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
       ' Loads the file into the control. 
       RichTextBox1.LoadFile(e.Data.GetData("Text"), System.Windows.Forms.RichTextBoxStreamType.RichText)
    End SubPrivate Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
       Dim Lb As ListBox
       Dim Pt As New Point(e.X, e.Y)
       Dim Index As Integer   ' Determines which item was selected.
       Lb = sender
       Index = Lb.IndexFromPoint(Pt)   ' Starts a drag-and-drop operation with that item.
       If Index >= 0 Then
          Lb.DoDragDrop(Lb.Items(Index), DragDropEffects.Link)
       End If
    End Sub[C#] 
    private void Form1_Load(object sender, EventArgs e) 
    {
       // Sets the AllowDrop property so that data can be dragged onto the control.
       richTextBox1.AllowDrop = true;   // Add code here to populate the ListBox1 with paths to text files.}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);
       int index = lb.IndexFromPoint(pt);   // Starts a drag-and-drop operation with that item.
       if(index>=0) 
       {
          lb.DoDragDrop(lb.Items[index].ToString(), DragDropEffects.Link);
       }
    }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) 
    {
       // Loads the file into the control. 
       richTextBox1.LoadFile((String)e.Data.GetData("Text"), System.Windows.Forms.RichTextBoxStreamType.RichText);
    }