TX Text Control allows you to protect documents with specific permissions and to protect documents from editing and formatting actions. Typically, a document is protected, exceptions are applied for specific users and the document is encrypted with a password. When opening such a document with TX Text Control without providing the master password, the permissions are applied and the document is protected automatically when the TXTextControl.TextControl.EditMode property TX Text Control .NET for Windows Forms
TXTextControl Namespace
TextControl Class
EditMode Property
Gets or sets a value indicating whether the document's text is protected, or can be freely edited and formatted.
is set to ReadAndSelect.

But the document permissions can be also used without encrypting the document. The following code shows how to prevent users from making formatting changes. The document content can be changed, but formatting actions are not allowed:

textControl1.DocumentPermissions.AllowFormatting = false;
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;
view raw data.cs hosted with ❤ by GitHub

If you want to save the permission settings in the document, the EditMode property must be set to ReadAndSelect and UsePassword. The document is then encrypted and the permissions are stored in the document.

textControl1.DocumentPermissions.AllowFormatting = false;
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect | EditMode.UsePassword;
textControl1.Save("test.tx", TXTextControl.StreamType.InternalUnicodeFormat);
view raw data.cs hosted with ❤ by GitHub

If this document is re-opened and and the EditMode is set to ReadAndSelect, the permissions are automatically applied:

textControl1.Load("test.tx", TXTextControl.StreamType.InternalUnicodeFormat, ls);
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;
view raw data.cs hosted with ❤ by GitHub

The included ribbon bar of TX Text Control is reflecting these document permissions automatically. After reloading the document into TX Text Control, the formatting options are disabled:

Document Protection

The document master password can also be set programmatically when loading the document. The following code shows how to save a read-only document with formatting restrictions:

textControl1.DocumentPermissions.AllowFormatting = false;
textControl1.DocumentPermissions.ReadOnly = true;
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect | EditMode.UsePassword;
textControl1.Save("test.tx", TXTextControl.StreamType.InternalUnicodeFormat);
view raw data.cs hosted with ❤ by GitHub

If this document is loaded without passing a password, the document cannot be edited or formatted. But if the document is opened with the correct master password, these restrictions are suspended:

LoadSettings ls = new LoadSettings()
{
MasterPassword = "123"
};
textControl1.Load("test.tx", TXTextControl.StreamType.InternalUnicodeFormat, ls);
textControl1.EditMode = TXTextControl.EditMode.ReadAndSelect;
view raw data.cs hosted with ❤ by GitHub

If you want to learn more about document protection, these 2 articles explain the basics of document protection:

Protected Documents Explained Simply

Protected Documents Explained Simply - Part II