Making whole lines read only

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Vincent Parrett
Version: 4.0.0253
Avatar
Hi

I would like to make the first and last lines in a document read only, such that the user can edit between the first and last lines but not on those lines and not after the last line.

The only way I have found that comes close is using ReadOnlySpanIndicators. Unfortunately this doesn't go far enough, as the user can still add text after the end of the line.

I can't use the Header/FooterText properties as they are not displayed in the editor(and I have another use for them), I would rather not use 3 controls to achieve this.

Ideally I'd like to be able to do something like :

//set the first line to read only
_document.Lines[0].IsReadOnly = true;

//set the last line as read only and absolute last line!
DocumentLine line = _document.Lines[_document.Lines.Count - 1];
line.IsReadOnly = true;
line.IsLastLine = true; //no further lines may be added after this line!

Any suggestions?

Thanks

Vincent.

Comments (2)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Vincent,

What you can do now is handle the DocumentPreTextChanging event and cancel the modification if it is on one of those two document lines. That would probably work best for your scenario.


Actipro Software Support

Posted 17 years ago by Vincent Parrett
Avatar
Thanks, that works well.. for anyone else interested here's what I came up with :

        private void Editor_DocumentPreTextChanging(object sender, DocumentModificationEventArgs e)
        {
            if (!_currentDoc.FirstLineEditable)
            {
                if (e.Modification.StartLineIndex == 0)
                {
                    if ((e.Modification.Type == DocumentModificationType.Enter) && (e.Document.Lines[0].IsLineEnd(e.Modification.StartOffset)))
                    {
                        return;
                    }
                    else
                    {
                        e.Cancel = true;
                        return;

                    }
                }
            }
            if (!_currentDoc.LastLineEditable)
            {

                if (e.Modification.StartLineIndex == e.Document.Lines[e.Document.Lines.Count -1].Index )
                {
                    if ((e.Modification.Type == DocumentModificationType.Enter) && (e.Document.Lines[e.Document.Lines.Count -1].IsLineStart( e.Modification.StartOffset)))
                    {
                        return;
                    }
                    else
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }
        }
The latest build of this product (v24.1.0) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.