Make document truly read-only

4 posts, 1 answers
  1. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 20 Feb Link to this post

    In Word-inspired project I want to display a document and prevent any modifications to it. If I set radRichTextEditor1.IsReadOnly = true then user cannot type in it, but commands from ribbon bar still work (text can be turned bold, for instance). How to disable all the commands from ribbon bar? My document already has document protection enabled, but it also has one permission range.

    Interestingly, looking into Telerik code, there is a RichTextBoxCommandBase.CanExecute method, but it's apparently being ignored, as ribbon bar commands are executed even when CanExecute returns false.

  2. Dimitar
    Admin
    Dimitar avatar
    2790 posts

    Posted 21 Feb Link to this post

    Hello Mihajlo,

    You can use the CommandExecuting event for this. For example: 
    private void RadRichTextEditor1_CommandExecuting(object sender, Telerik.WinForms.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
    {
       e.Cancel = radRichTextEditor1.IsReadOnly;
    }

    Another approach would be to hide or disable the ribbon or the ribbon tabs when such document is loaded. 

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 21 Feb in reply to Dimitar Link to this post

    Right, but that would disable Copy and Find commands. The code below should fix it probably, but I suggest this code run before even reaching CommandExecuting handler:

    e.Cancel = !e.Command.CanExecute(e.CommandParameter);

     

    Even with this fix there is still a small annoyance that toggle buttons (like Bold) change their toggle state when clicked on protected document. Nothing will happen to the document, and once caret is moved toggle state will be restored, but it looks strange at first. As a reference, Word will disable all appropriate buttons when caret is in protected part of the document.

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2790 posts

    Posted 21 Feb Link to this post

    Hello Mihajlo,

    Ok, I have logged this for improvement on our Feedback Portal. You can track its progress, subscribe to status changes and add your comment to it here. I have also updated your Telerik Points.

    Until this is implemented you can use the bellow approach as a workaround. 

    Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top