How to prevent copy and paste richtext to richtextbox?

I am using richtextbox for the user to enter plaintext.
The reason I am using richtextbox is because the scrollbar of richtextbox is automatically appear and disappear depends on the length of word, but textbox's scrollbar is always there.
But the problem is, the user still can copy and paste the formatted text(Bold, italic, etc) to the richtextbox. Is there a way to make all the copied formatted text paste as plain text, or any other mean in order to make the richtextbox not to show the richtext?
LVL 9
william007Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
The text is an RTF box is always formatted, but if all the text has the same font characteristics, you won't notice it.

This will help to keep the formatting consistent. The list of properies is not exhaustive, however and you may need to add more.

Private Sub RichTextBox1_Change()
    Dim s As Long
    Dim l As Long
    Dim l2 As Long
    s = RichTextBox1.SelStart
    l = RichTextBox1.SelLength
    l2 = Len(RichTextBox1.Text)
    RichTextBox1.SelStart = 0
    RichTextBox1.SelLength = l2
       With RichTextBox1
          .SelFontName = "MS Sans Serif"
          .SelFontSize = 8
          .SelBold = False
          .SelItalic = False
          .SelStrikeThru = False
          .SelUnderline = False
       End With
    RichTextBox1.SelStart = s
    RichTextBox1.SelLength = l
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anthony2000Commented:
If you want to disable pasting to the RichTextBox both from using the RichTextBox's context menu and the keyboard:

Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
   Debug.Print KeyCode ' so I could see what code ctrl-v produced, I found it to be 86
   If KeyCode = 86 Then
      KeyCode = 0 ' cancel the ctrl-v (paste)
   End If
End Sub

as for right-mouse content menu, I modified the RichTextBox's
AutoVerbMenu and set it to False

Otherwise, you can trap on the WM_PASTE message using a subclassing technique (see http://support.microsoft.com/kb/q179398/). This maybe more complicated than you want.

Anthony


Anthony

0
william007Author Commented:
Thanks:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.