PrintDocument for WinForms | ComponentOne
In This Topic
    Quick Start
    In This Topic

    This quick start gets you started with PrintDocument by letting you create a WinForms application, add printing and previewing controls to it, set up the preview and explore some of the run-time interactions available in the previewing controls.

    PrintDocument application

    To quickly get started using the library, follow these steps:

    Add PrintDocument and PrintPreview

    1. Create a Windows Forms App in Visual Studio.
    2. Add reference to C1.Win.Printing NuGet package.
    3. Drag and drop the PrintPreviewControl from Toolbox to the form. The PrintPreviewControl control is a composite control containing a preview pane, navigation and text search panels, and toolbars with predefined buttons.
    4. Drag and drop the PrintDocument component from the Toolbox to your form. You can observe that PrintDocument gets added to the component tray.

    Configure the form and controls

    1. Right-click the form and navigate to the Properties window, and set the Size.Width property to 600 pixels and the Size.Height property to 400 pixels to accommodate the size of the PrintDocument component.           
    2. Click PrintPreviewControl's smart tag to open the PrintPreviewControl's Tasks menu and select Dock in Parent Container.               
    3. Click PrintPreviewControl to select it and in the Properties window set its Document property to the newly added PrintDocument component. The selected document, here C1PrintDocument1, will show in the preview window at run time.
    4. Switch to the code view and add C1.Preview namespace:
      C#
      Copy Code
      using C1.C1Preview;
      
    5. Add the following code to the Form_Load event to add text to the preview document and generate the document.
      C#
      Copy Code
      private void Form1_Load(object sender, EventArgs e)
      {
          this.c1PrintDocument1.Body.Children.Add(new RenderText("Hello, World!"));
          this.c1PrintDocument1.Generate();
      }
      

    Build and Run the Project

    1. Click Build | Build Solution to build the project.
    2. Press F5 to run the project.
    3. Observe some of the run-time interactions with the previewing controls

      PrintDocument control