ReadOnly, Locked, SelProtected Property, Protected event

Purpose

Returns or sets the read-only style of (part of) the text of an edit control.

Syntax

Object.ReadOnly [ = Boolean]

RichEdit.Locked [= boolean]

RichEdit.SelProtected [= variant]

Sub RichEdit_Protected(Start&, End&, Cancel?)

Object: TextBox, RichEdit Ocx

Description

ReadOnly returns or sets the read-only style (ES_READONLY) of an edit control. With this style you cannot change the text within the edit control.

Locked returns or sets a value indicating whether the contents in a RichEdit control can be edited. You can scroll and highlight the text in the control, but you can't edit it. The program can still modify the text by changing the Text property.

SelProtected returns or sets a value which determines if the current selection is protected. Protected text looks the same a regular text, but cannot be modified by the end-user. That is, the text cannot be changed during run time. This allows you to create forms with the RichRdit control, and have areas that cannot be modified by the end user. SelProtected can return Null meaning that the selection contains a mix of protected and non-protected characters. It can be assigned a Boolean, meaning (True) that all the characters in the selection are protected, or (False) none of the characters in the selection are protected.

The Protected event notifies that the user is taking an action that would change a protected range of text. The Cancel? parameter provides the event the means to allow or prevent the change. Set Cancel? = False to accept the change.

Example

Local n As Int32

Ocx RichEdit rtb = "", 10, 10, 200, 300 : rtb.MultiLine = True : rtb.BorderStyle = 1 : rtb.ScrollBars = 2

For n = 1 To 100 : rtb.Text = rtb.Text & "This is a rich text edit box" & #13#10  : Next n

Ocx CheckBox chk(1) = "Locked", 230, 10, 100, 14

Ocx CheckBox chk(2) = "Read Only", 230, 30, 100, 14

Ocx Command cmd = "Protect Selection", 230, 50, 100, 22 : cmd.Enabled = False

Do : Sleep : Until Me Is Nothing

 

Sub chk_Click(Index%)

rtb.Locked = -chk(1).Value

rtb.ReadOnly = -chk(2).Value

EndSub

 

Sub cmd_Click

rtb.SelProtected = True

EndSub

 

Sub rtb_MouseUp(Button&, Shift&, x!, y!)

If Not cmd Is Nothing

cmd.Enabled = (rtb.SelLength = 0 ? False : True)

EndIf

EndSub

 

Sub rtb_Protected(Start%, End%, Cancel?)

If MsgBox("An attempt was made to edit or access Protected text"#13#10#13#10 & _

"Do you wish to continue with the deletion?", MB_YESNO, "Confirm Delete") = IDNO

Cancel? = True

EndIf

EndSub

See Also

TextBox, RichEdit

{Created by Sjouke Hamstra; Last updated: 22/10/2014 by James Gaite}