Click here to Skip to main content
Licence GPL3
First Posted 7 Apr 2008
Views 13,683
Bookmarked 10 times

How to make content of RichTextBox unselectable.

By , | 7 Apr 2008 | Article
you want to display some text in your application and side-by-side you want to prevent the user from copying the content. . One way to implement this use label, but label do not support the formatting of the text and RTF formats.

Download Source Code


Introduction

How to make content of RichTextBox unselectable.

In many situations, if you want to display some text in your application and side-by-side you want to prevent the user from copying the content. One way to implement this use label, but label do not support the formatting of the text and RTF formats. So in that case this simple tutorial can solve the problem completely.

This tutorial explains the way of using a RichTextBox and it also makes the text unselectable.


Using the code

‘The project starts from here.

‘Create a VB.NET solution.
‘You will see a form1 in it.
‘Now Add Richtextbox1 to this form.
‘Name it as richtextbox1.
‘Add a Label, Name it as Label1.

‘Now add few Events to source code.

‘Form load event

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

RichTextBox1.Rtf = File.ReadAllText("c:\m1.rtf") ‘input file in rtf format

RichTextBox1.ReadOnly = True
RichTextBox1.BorderStyle = BorderStyle.None ‘optional
RichTextBox1.WordWrap = True ‘optional

End Sub

‘Add events to Richtextbox1

Private Sub RichTextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.GotFocus

RichTextBox1.SelectionLength = 0
Label1.Focus()

End Sub

Private Sub RichTextBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDoubleClick

RichTextBox1.SelectionLength = 0
Label1.Focus()

End Sub

Private Sub RichTextBox1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RichTextBox1.SelectionChanged

RichTextBox1.SelectionLength = 0
Label1.Focus()

End Sub

Points of Interest

Just play more with .NET controls.

Just visit IPStudents.info for more exciting codes on VB.NET ,PHP and more...

History

First and I guess Last version...

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Authors

chanderp

Software Developer

India India

Member

IPStudents.Info - Its all about creativity and ideas.

Yash Bharadwaj

Software Developer
Speedovation
India India

Member

Follow on Twitter Follow on Twitter
CssEditor.In - Wait less code more.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralVB.NET Pinmemberabowzer adam hassan1:33 17 Jun '08  
GeneralRe: VB.NET Pinmemberksor hien0:43 4 Jun '09  
Generalhi PinmemberESTAN23:05 7 Apr '08  
GeneralRe: hi Pinmemberchanderp2:44 8 Apr '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 8 Apr 2008
Article Copyright 2008 by chanderp, Yash Bharadwaj
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid