RichTextBox <ctrl>V pastes 2 copies, <alt>EP pastes 1 copy 
Author Message
 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



Wed, 16 Nov 2005 00:51:14 GMT  
 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.

Unlike the standard textbox the RTF supports <Ctrl>V <Ctrl>C etc...
so if there is a menu with shortcuts cut,copy,paste then it will
double up if you code it also.
A flag set true (say flgControlKeyPressed) on keydown and false on keyup
will filter it.
You may want to look at using API for most of this as it supports a limited
undo also.

    Select Case Index
        Case mUndo
            EditPerform WM_UNDO
        Case mCut
            EditPerform WM_CUT
        Case mCopy
            EditPerform WM_COPY
        Case mPaste
            EditPerform WM_PASTE
        Case mDelete
            EditPerform WM_CLEAR
    End Select

Sub EditPerform(EditFunction As Integer)
    If TypeOf Me.ActiveControl Is TextBox Then
        Call SendMessage(Me.ActiveControl.hWnd, EditFunction, 0, 0&)
    ElseIf TypeOf Me.ActiveControl Is RichTextBox Then
        'Only sends msg if no cotnrol key pressed
        If  Not flgControlKeyPressed  Then
            Call SendMessage(Me.ActiveControl.hWnd, EditFunction, 0, 0&)
        End If
    Else
        Beep
    End If
End Sub

If needed you can set an undo menu with this when called
mnu_Edit(mUndo).Enabled = SendMessage(Me.ActiveControl.hWnd, EM_CANUNDO, 0,
0&)
--
HTH
Geoff



Wed, 16 Nov 2005 03:18:12 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. <<<<<<<<ComboBox>>>>>>>>>>>>

2. HELP >>>>>>WIN API <<<<<<<<<<

3. RTF textbox <> copy/paste problem

4. help me out please!!!!<<<<<<<<<<<<<<<<<<<<<<<thanks>>>>>>>>>>>>>>>>>>>>>>>>

5. <><><>HELP<><><> PCMCIA Motorola Montana 33.6

6. Restoring my <CTRL+V> paste command

7. <<<<HELP- OLE container Control>>>>>>>>>

8. VB5<->RDO2<->ODBC<->ORACLE Procedure Problem

9. <<<Cneck Box>>>

10. <<<Gif Files>>>

11. <<<CD ROM>>>

12. <<<Win32Api.TXT>>>

 

 
Powered by phpBB® Forum Software