You cannot drop text in a RichTextBox control by using a code sample from MSDN documentation (814309)
The information in this article applies to:
- Microsoft Visual Basic 2005
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual C# 2005, Express Edition
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
Beta Information This article discusses a Beta release of a Microsoft
product. The information in this article is provided as-is and is subject to
change without notice.
No formal product support is available from
Microsoft for this Beta product. For information about how to obtain support
for a Beta release, see the documentation that is included with the Beta
product files, or check the Web location from which you downloaded the release.
SYMPTOMSYou try to drag a RichTextBox control with the code in the "Enabling Drag-and-Drop Operations
with the Windows Forms RichTextBox Control" MSDN document. The change may occur
in the pointer when you drag the text from WordPad. However, you cannot drop
the text from the RichTextBox. CAUSEThis problem occurs because there is no code for the Drop event in MSDN documentation. Therefore, you cannot drop the text
that you select from WordPad in the RichTextBox.RESOLUTIONTo work around this problem, add a DragDrop event for RichTextBox1. To do this, use the following instructions. Visual Basic .NET or Visual Basic 2005Add the following code in the RichTextBox1
DragDrop event: Dim i As Int16
Dim s As String
' Get Start Position For the for Dropping the Text
i = RichTextBox1.SelectionStart
s = RichTextBox1.Text.Substring(i)
RichTextBox1.Text = RichTextBox1.Text.Substring(0, i)
' Drop the Text on to the RichTextBox
RichTextBox1.Text = RichTextBox1.Text + e.Data.GetData(DataFormats.Text).ToString()
RichTextBox1.Text = RichTextBox1.Text + s
Visual C# .NET or Visual C# 2005Add the following code to the Form1 class constructor after the InitializeComponent() statement: // Handler for DragDrop event
this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.rtb_dragdrop); Add the following procedure to the code after the Main() method: private void rtb_dragdrop(object sender,DragEventArgs e)
{
int i;
String s;
// Get Start Position to Drop the Text
i = richTextBox1.SelectionStart;
s = richTextBox1.Text.Substring(i);
richTextBox1.Text = richTextBox1.Text.Substring(0,i);
// Drop the Text on the RichTextBox
richTextBox1.Text = richTextBox1.Text + e.Data.GetData(DataFormats.Text).ToString();
richTextBox1.Text = richTextBox1.Text + s;
} STATUS This
behavior is by design.
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbvs2005swept kbvs2005applies kbprb kbWindowsForms kbProperties kbEvent kbRichEdit kbDragDrop KB814309 kbAudDeveloper |
---|
|