Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Collapse]Printing-Exporting
   [Expand]Product Information
   [Expand]Getting Started
   [Expand]Fundamental Concepts
   [Expand]Concepts
   [Collapse]Examples
    [Expand]Print Preview
    [Expand]Using Bricks
    [Expand]Using Printing Links
    [Expand]Page Header and Footer
    [Expand]Printing DevExpress Controls
    [Expand]Exporting
    [Collapse]Miscellaneous
      How to: Create an Interactive Drill-Down Report
      How to: Create a Document Map (Bookmarks)
      How to: Calculate Page and Report Summaries
      How to: Add a Watermark to a Document
      How to: Save and Restore a Document's Watermark in Print Preview
      How to: Add Different Watermarks to Document Pages
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Save and Restore a Document's Watermark in Print Preview

This tutorial demonstrates how to save and load a document's watermark, which is specified in Print Preview, to/from a system registry, XML file, or memory stream.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E1909.

To save and load a document's watermark, do the following.

  1. In Visual Studio, create a new Windows Forms Application.

  2. From the DX.17.1: Data & Analytics Toolbox tab, drop a GridControl onto a form, and bind it to a data source. A report document will be generated based on it later in code.

  3. To add a print preview to your application, switch to the application's main form in Visual Studio, and press CTRL+ALT+X to run the Toolbox. Expand the DX.17.1: Reporting category and drop the DocumentViewer control onto the form.

  4. Click the smart tag of the control, and in the invoked actions list, select a toolbar that matches the user interface style of the rest of your application. In this tutorial, the ribbon toolbar is preferred over the minimal bar interface.

  5. To assign a document source to the control, click its smart tag again. In the drop-down menu of the DocumentViewer.DocumentSource property, expand the Standard Sources category and select PrintingSystem.

  6. Click the Printing System's smart tag and click ellipsis button for the PrintingSystem.Links property. In the invoked dialog, add a new PrintableComponentLink instance. Set its PrintableComponentLinkBase.Component property to gridControl1.

  7. Next, from the DX.17.1: Common Controls Toolbox tab, drop the SimpleButton and RadioGroup controls onto the form.

    Select the radioGroup1, and in the Properties window, expand its RadioGroup.Properties, and click the ellipsis button for the RepositoryItemRadioGroup.Items property.

    In the invoked dialog, create three items with the following RadioGroupItem.Description property values.

    - Save/Load from Registry

    - Save/Load from XML

    - Save/Load from Stream

    For the radioGroup1, you may also wish to set the RepositoryItemRadioGroup.Columns property to 3, to better position its items within the form.

  8. Now, let's declare three storages (corresponding to a registry, file, or stream), and write two private methods (SaveWatermark and RestoreWatermark), which save/restore a PrintingSystem's watermark (the PrintingSystemBase.Watermark property value) to/from these storages, using the Watermark.SaveToRegistry, Watermark.SaveToXml, and Watermark.SaveToStream methods, correspondingly.

  9. Now, assign an appropriate storage to each RadioGroup's item.

  10. In the form's Load event handler, specify options for the default watermark, and save them to all available storages.

  11. Now, handle the Click event of the simpleButton1, to call the RestoreWatermark method, create a report document (by calling the PrintableComponentLink.CreateDocument method) and handle the FormClosed event of the PrintingSystem.PreviewFormEx.

    Finally, call the Link.ShowPreview method.

  12. Lastly, write the FormClosed event handler for the Preview form, where the watermark is saved to the specified storage.

Run the application. Choose a storage using the radio buttons, and click Show Preview. Then, in the invoked Print Preview form, access and specify the document's watermark options (by clicking the Watermark toolbar button, or by choosing Watermark... entry in the Background menu).

In the invoked Watermark dialog, customize the default watermark, and click OK. Now, close the Print Preview form, and click the Show Preview button again, to see that the changes being made to the watermark are still in effect.

Expanded See Also

How would you rate this topic?​​​​​​​