
RichTextBox <ctrl>V pastes 2 copies, <alt>EP pastes 1 copy
Quote:
>Strictly as a learning exercise in VB 5 I've been writing a clone of
>notepad which will handle really big files. Pretty much everything
>seems to be working and then I found that <ctrl>V pastes two copies
>of the clipboard into the RichTextBox while <alt>EP works correctly.
>This is the code, looks simple enough:
>Private Sub mnuPaste_Click()
> Dim s As String
> s = Clipboard.GetText()
> RichTextBox1.SelText = s
> filechanged = True
>End Sub
>I've tried searching Microsoft's database and can't find any notes
>about this. Does anyone have any idea what I've done wrong?
>It just looks too simple to have missed something. But maybe there
>is something about RichTextBox that I've misunderstood.
>Thanks
I don't have the problem of repeats using <Ctrl>V but the RichTextBox is kind of flaky... ;-<
I started using the API's to do most functions in the RTB because they seem to go around the VB ones..
Here is an example:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_PASTE = &H302
Private Sub Command1_Click()
SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0
End Sub
If you want to paste an image into it do the following:
Note: this is the easiest way I know of to do this...
Private Sub Command2_Click()
' Copy the picture into the clipboard.
Clipboard.Clear
Clipboard.SetData Picture1.Picture
' Paste the picture into the RichTextBox.
SendMessage RichTextBox1.hwnd, WM_PASTE, 0, 0
End Sub
Just food for thought and something to play with.
Have a good day...
Don