This is a migrated thread and some comments may be shown as answers.

Disable print dialog and print settings dialog from print preview dialog

1 Answer 91 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Mihajlo
Top achievements
Rank 1
Mihajlo asked on 17 Aug 2018, 04:04 PM

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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 20 Aug 2018, 08:43 AM
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.
Tags
RichTextEditor
Asked by
Mihajlo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or