Print settings

9 posts, 0 answers
  1. Alex Dybenko
    Alex Dybenko avatar
    119 posts
    Member since:
    Jan 2005

    Posted 21 Oct Link to this post

    Hi,

    is it an easy way to save/load all print settings for PivotGrid?

    Thanks

    Alex

     

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 24 Oct Link to this post

    Hi Alex,

    Thank you for writing.

    Currently, we are not having a persistence API of RadPivotGrid`s print settings. You can, however, save the property values of the RadPrintDocument and PivotGridPrintStyle instances.

    A suitable place to perform this logic is the OnBeginPrint method of the RadPrintDocument  class. This way you will be sure that the saved values are always the newest reflecting the changes performed by the end users: 
    // In your pivot form
    private void PrintPivotGrid()
    {
        RadPrintDocument document = new MyRadPrintDocument();
        document.DefaultPageSettings.Landscape = true;
        document.DefaultPageSettings.PrinterSettings.Copies = 2;
        document.AssociatedObject = this.radPivotGrid1;
     
        PivotGridPrintStyle style = new PivotGridPrintStyle();
        style.LayoutType = PivotLayout.Compact;
        this.radPivotGrid1.PrintStyle = style;
     
        RadPrintPreviewDialog dialog = new RadPrintPreviewDialog();
        dialog.Document = document;
        dialog.ShowDialog();
    }
    public class MyRadPrintDocument : RadPrintDocument
    {
        protected override void OnBeginPrint(System.Drawing.Printing.PrintEventArgs e)
        {
            base.OnBeginPrint(e);
     
            PivotGridPrintStyle style = ((RadPivotGrid)this.AssociatedObject).PrintStyle;
            // Save settings from the print and style objects.
        }
    }

    I hope this information is useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Alex Dybenko
    Alex Dybenko avatar
    119 posts
    Member since:
    Jan 2005

    Posted 25 Oct in reply to Hristo Merdjanov Link to this post

    Hi Hristo,

    Thanks! Perhaps you can also show me how to add Save button to print settings dialog, so I can use it to save settings?

    Alex

     

  5. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 25 Oct Link to this post

    Hello Alex,

    Thank you for writing back.

    You can create a new CommandBarButton and add it to any of the strips of the RadCommandBar control used by the RadPrintPreviewDialog:
    RadPrintPreviewDialog dialog = new RadPrintPreviewDialog();
    CommandBarButton saveBtn = new CommandBarButton();
    saveBtn.Click += saveBtn_Click;
    dialog.ToolCommandBar.Rows[0].Strips[0].Items.Add(saveBtn);
     
    I hope this helps. Please let me know if you need further assistance.
    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  6. Alex Dybenko
    Alex Dybenko avatar
    119 posts
    Member since:
    Jan 2005

    Posted 26 Oct in reply to Hristo Merdjanov Link to this post

    Hi Hristo,

    thanks, but is it possible to add button to Print settings dialog? See attached

     

    Alex

     

     

  7. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 27 Oct Link to this post

    Hello Alex,

    Thank you for writing.

    In order to add an additional button to the PrintSettingsDialog, you need to create a custom RadPrintPreviewDialog and override its OnShowPrintSettingsDialog method. Please check my code snippet below: 
    public class MyRadPrintPreviewDialog : RadPrintPreviewDialog
    {
        protected override void OnShowPrintSettingsDialog()
        {
            if (this.Document == null)
            {
                return;
            }
     
            Form dialog = this.Document.AssociatedObject.GetSettingsDialog(this.Document);
            RadForm radDialog = dialog as RadForm;
     
            RadButton print = radDialog.Controls["buttonPrint"] as RadButton;
            RadButton saveBtn = new RadButton() { Text = "MyBtn" };
            saveBtn.Parent = radDialog;
            saveBtn.Size = print.Size;
            saveBtn.Location = new Point(print.Location.X - print.Size.Width - 6, print.Location.Y);
            saveBtn.Click += saveBtn_Click;
     
            if (radDialog != null)
            {
                radDialog.ThemeName = this.ThemeName;
            }
     
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.Document.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.AllPages;
                this.printPreviewControl.InvalidatePreview();
                this.GetType().BaseType.GetMethod("UpdatePageCount", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[] { });
            }
        }
     
        private void saveBtn_Click(object sender, EventArgs e)
        {
            //...
        }
    }

    I am also sending you a screenshot showing the result on my end.

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  8. Alex Dybenko
    Alex Dybenko avatar
    119 posts
    Member since:
    Jan 2005

    Posted 27 Oct in reply to Hristo Merdjanov Link to this post

    Hi Hristo,

    Exactly what I need! One more thing - changes on Print setting dialog are applied to RadPrintDocument after you press Print or Preview, is it possible to call buttonPreview_Click (whatever it called) from saveBtn_Click? So the idea that saveBtn will work like MS Word "Set as default" button: in saveBtn_Click i call buttonPreview_Click, dialog is closed, user get back to preview and then i call my method SavePrintSettings()

    Thanks

    Alex

     

  9. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 28 Oct Link to this post

    Hello Alex,

    Thank you for writing back.

    There is no way to preview the changes without actually applying them to the document. I can suggest adding your save logic at the end of the OnShowPrintSettingsDialog method. This way it will be always in sync with the printed or previewed document. Additionally, you may also consider adding the button in the command bar as I suggested in my second post.

    In case that does not fit your project and you insist on using the separate button you can apply and save the changes this way: 
    public class MyRadPrintPreviewDialog : RadPrintPreviewDialog
    {
        Form dialog;
        protected override void OnShowPrintSettingsDialog()
        {
            if (this.Document == null)
            {
                return;
            }
     
            dialog = this.Document.AssociatedObject.GetSettingsDialog(this.Document);
            RadForm radDialog = dialog as RadForm;
     
            RadButton print = radDialog.Controls["buttonPrint"] as RadButton;
     
            RadButton saveBtn = new RadButton() { Text = "MyBtn" };
            saveBtn.Parent = radDialog;
            saveBtn.Size = print.Size;
            saveBtn.Location = new Point(print.Location.X - print.Size.Width - 6, print.Location.Y);
            saveBtn.Click += saveBtn_Click;
     
            if (radDialog != null)
            {
                radDialog.ThemeName = this.ThemeName;
            }
     
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.Document.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.AllPages;
                this.printPreviewControl.InvalidatePreview();
                this.GetType().BaseType.GetMethod("UpdatePageCount", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[] { });
            }
        }
     
        private void saveBtn_Click(object sender, EventArgs e)
        {
            typeof(PrintSettingsDialog).GetMethod("ApplySettings", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(dialog, new object[] { });
     
            this.Document.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.AllPages;
            this.printPreviewControl.InvalidatePreview();
            this.GetType().BaseType.GetMethod("UpdatePageCount", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[] { });
     
            //Execute your logic for saving the settings
     
            dialog.Close();
        }
    }

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  10. Alex Dybenko
    Alex Dybenko avatar
    119 posts
    Member since:
    Jan 2005

    Posted 02 Nov in reply to Hristo Merdjanov Link to this post

    Thanks Hristo, works great!

    Alex

Back to Top
UI for WinForms is Visual Studio 2017 Ready