Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
How to make content of RichTextBox unselectable
Author:
Yash Bhardwaj
E-mail:
Click to e-mail author
Website:
http://IPStudents.info
Submitted:
4/8/2008
Version:
VB6
Compatibility:
VB6
Category:
Controls
Views:
11360
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.
Declarations:
'none
Code:
'IPStudents.Info - Its all about creativity and ideas. 'Author : Yash Bharadwaj 'Copyright : Free to use 'Summary: How to make content of RichTextBox unselectable. 'Usage : Just use focus event. '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 'input file in rtf format RichTextBox1.Rtf = File.ReadAllText("c:\m1.rtf") 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
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement