RichTextBox1.Rtf = RtfText appends it ???

  • Thread starter Thread starter SamSpade
  • Start date Start date
S

SamSpade

When I do

RichTextBox1.Rtf = e.Data.GetData(DataFormats.Rtf).ToString

it appears to me that the text is being appended to the text already in the
box.

Help is not clear on this.

Can anyone confirm that that is what is to be expected???

I had guessed that the new text would replace the contents, not add to it.

Of course I could clear the box first I just want to be sure I surmised
correctly.

I assume the Text property acts the same as the Rtf. Correct??



Thanks in advance
 
* " SamSpade said:
RichTextBox1.Rtf = e.Data.GetData(DataFormats.Rtf).ToString

it appears to me that the text is being appended to the text already in the
box.

Help is not clear on this.

Can anyone confirm that that is what is to be expected???

Where did you place this code?!
 
After stripping it down I have the following. If I run it as is and drag XYZ
from a wordpad document I get XYZXYZ.

I found that the DragDrop routine is entered twice, once with e.Effect=None
and then with e.Effect=Copy

I don't know why that happens but think that the second time should reset
the text to XYZ not XYZXYZ

As to why it enters twice I found that if I remove e.Effect =
DragDropEffects.Copy from DragDrop it is only entered once and XYZ shows.

So you see there are two questions:
How does XYZXYZ ever get into the box
Why is it entered twice if e.Effect = DragDropEffects.Copy


Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter,
RichTextBox1.DragEnter
e.Effect = e.AllowedEffect And DragDropEffects.Copy
End Sub

Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop,
RichTextBox1.DragDropAnd 32) Then '32=Alt
e.Effect = DragDropEffects.Copy
If e.Data.GetDataPresent(DataFormats.Rtf) Then
RichTextBox1.Rtf = e.Data.GetData(DataFormats.Rtf).ToString
Else
RichTextBox1.Text = e.Data.GetData(DataFormats.Text).ToString
End If
End Sub
 
Noticed my Cut and paste let sometine to be desired. Fixed below.
Still the 2 questions are unanswered by me.

Also, if I type Handles RichTextBox1. the dropdown box includes the Drag
events.

But if I select RichTextBox1 in the Class Name dropdown box the events do
not show up in the Method Name box.




SamSpade said:
After stripping it down I have the following. If I run it as is and drag XYZ
from a wordpad document I get XYZXYZ.

I found that the DragDrop routine is entered twice, once with e.Effect=None
and then with e.Effect=Copy

I don't know why that happens but think that the second time should reset
the text to XYZ not XYZXYZ

As to why it enters twice I found that if I remove e.Effect =
DragDropEffects.Copy from DragDrop it is only entered once and XYZ shows.

So you see there are two questions:
How does XYZXYZ ever get into the box (even if entered twice)
Why is it entered twice when e.Effect = DragDropEffects.Copy

Private Sub RichTextBox1_DragOver(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragOver

e.Effect = e.AllowedEffect And DragDropEffects.Copy
End Sub

Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
e.Effect = DragDropEffects.Copy
If e.Data.GetDataPresent(DataFormats.Rtf) Then
RichTextBox1.Rtf = e.Data.GetData(DataFormats.Rtf).ToString
Else
RichTextBox1.Text = e.Data.GetData(DataFormats.Text).ToString
End If
End Sub
 
Back
Top