Stop user editing text in rich text box

Android

Active member
Joined
Mar 6, 2007
Messages
35
Programming Experience
1-3
Is it possible to stop the user from editing the contents of a rich text box?
I tried disabling it but I don't want the grey back colour and the scroll bars still need to work. Is there anyway that I can achieve this?

Thanks.
 
I've been using an inherited RichTextBox in some projects to disallow editing, as a rich text display box, but still allow user to select and copy text. This is the code, it should be easy to modify if you need to turn the feature on/off.
VB.NET:
Public Class myRichTextBox
    Inherits RichTextBox
    [COLOR=darkgreen]'a richtextbox that don't accept user input or deletion, nor cut/paste/undo[/COLOR]
    Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        e.Handled = True [COLOR=darkgreen]'no typing[/COLOR]
        MyBase.OnKeyPress(e)
    End Sub
    Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.Control = True Then
            Select Case e.KeyCode
                Case Keys.V, Keys.X, Keys.Z [COLOR=darkgreen]'no paste/cut/undo[/COLOR]
                    e.Handled = True
            End Select
        End If
        Select Case e.KeyCode
            Case Keys.Delete, Keys.Back [COLOR=darkgreen]'no delete/backspace[/COLOR]
                e.Handled = True
        End Select
        MyBase.OnKeyDown(e)
    End Sub
End Class
 
Thanks, that worked perfectly.
Is there anything that I can do to stop them resizing the images though?
 
Use a web broswer control instead; the web pages it shows and the images are read only by design
 
Webbrowser could in some cases be an option, but also harder to manipulate/generate rich text, it would also normally flicker a lot when adding text to re-navigate. Most communication apps like MSN Messenger and IRC apps use a rich text box of some kind to display and add message lines continually, this was more like what I had in mind.
 
Back
Top