Disable print dialog and print settings dialog from print preview dialog

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

    Posted 17 Aug 2018 Link to this post

    I have a rich text editor with rubber bar (playing with Telerik's demo project), and I would like to disable the user from changing printer settings (and to change the printer in particular). So, for plain print I have this code (please correct me if there's a better way):

    private void radRichTextEditor1_CommandExecuting(object sender, CommandExecutingEventArgs e)
    {
      if (e.Command is PrintCommand)
      {
        e.Cancel = true;
        radRichTextEditor1.Print(false);
      }
    }

     

    But how to prevent the print dialog from print preview dialog? Also, how to prevent print settings dialog as well? Ideally I would like the print button to just print immediately, and print settings button to disappear.

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2823 posts

    Posted 20 Aug 2018 Link to this post

    Hi Mihajlo,

    This can be achieved by manually showing the print preview dialog. This way you can access the controls and hide the settings button. In addition, you should create a custom RadPrintPreviewDialog to intercept the print button and print without showing the settings. Here is a complete example of this:
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
            radRichTextEditor1.CommandExecuting += RadRichTextEditor1_CommandExecuting;
             
        }
     
        private void RadRichTextEditor1_CommandExecuting(object sender, Telerik.WinForms.Documents.RichTextBoxCommands.CommandExecutingEventAr
        {
            if (e.Command is PrintCommand)
            {
                e.Cancel = true;
                radRichTextEditor1.Print(false);
            }
            else if (e.Command is PrintPreviewCommand)
            {
                e.Cancel = true;
                var document = new RadPrintDocument();
     
                document.AssociatedObject = radRichTextEditor1.RichTextBoxElement;
                MyRadPrintPreviewDialog dialog = new MyRadPrintPreviewDialog(document);
                var commandaBar = dialog.Controls[1] as RadCommandBar;
                commandaBar.Rows[0].Strips[0].Items[1].Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
     
                dialog.ShowDialog();
                
            }
        }
    }
    class MyRadPrintPreviewDialog : RadPrintPreviewDialog
    {
        public MyRadPrintPreviewDialog(RadPrintDocument doc) : base (doc)
        {
     
        }
        protected override void OnShowPrintDialog()
        {
            //base.OnShowPrintDialog();
            this.Document.CurrentPage = this.printPreviewControl.StartPage + 1;
            this.Document.SelectionLength = this.printPreviewControl.Rows * this.printPreviewControl.Columns;
            this.Document.Print();
        }
    }

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

    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