Plaintext only in RichTextBox

CForrester
06-12-2006, 01:51 PM
Hey, I was wondering... Is there a way to ONLY allow plaintext in a RichTextBox? I'm making a simple Notepad application, but I don't want it to allow images or any sort of text formatting. I'd use a regular textbox, but I need RichTextBox's .Find sub.

I tried selecting all of the text and setting the text colour to black for the TextChanged event, but that causes terrible flickering whenever the text is changed, and moving the caret back to its previous position is a little glitchy...

There's also the problem of preventing images from being dropped in (I want to be able to drag and drop text)...

Thanks. :)

MikeJ
06-12-2006, 05:14 PM
You could always add your own .Find method to an inherited Textbox... Just look for IndexOf and add some of the other features to your liking. Seems like it'd be easier than having to block all of the RichTextBox's features. (Besides, that's why .NET is so much better than VB6 - easy modification of controls.)

CForrester
06-13-2006, 05:14 AM
You could always add your own .Find method to an inherited Textbox... Just look for IndexOf and add some of the other features to your liking. Seems like it'd be easier than having to block all of the RichTextBox's features. (Besides, that's why .NET is so much better than VB6 - easy modification of controls.)
That's a good idea, but I actually managed to get less work to do by doing this. :)

I made a custom Paste sub that does this:

Public clipboardtext As String
Public Sub Paste()
Dim data As IDataObject = Clipboard.GetDataObject
If data.GetDataPresent(DataFormats.Text, False) Or data.GetDataPresent(DataFormats.UnicodeText, False) Or data.GetDataPresent(DataFormats.Rtf, False) Then
clipboardtext = data.GetData(DataFormats.Text, True).ToString
Else
clipboardtext = ""
End If
rtbText.SelectedText = clipboardtext
clipboardtext = ""
End Sub


Next, I customized dragging and dropping with this:

Private Sub rtbText_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles rtbText.DragEnter
If e.Data.GetDataPresent(DataFormats.Text, True) Or e.Data.GetDataPresent(DataFormats.UnicodeText, False) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub


Now, I don't see any way for the user to put non-plaintext in the RichTextBox. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum