Reports for WinForms | ComponentOne
Reports for WinForms Top Tips / Visual Previewing Control Tips
In This Topic
    Visual Previewing Control Tips
    In This Topic

    The following tips relate to the visual previewing controls included in Reports for WinForms (such as C1PrintPreviewControl, C1PrintPreviewDialog, C1PreviewPane, C1PreviewThumbnailView, C1PreviewOutlineView, and C1PreviewTextSearchPanel).

    Tip 1: Adding a Custom Toolbar Button to C1PrintPreviewControl

    You may want to customize a toolbar in the C1PrintPreviewControl control by adding a custom button. To add your own toolbar button to any of the built-in toolbars on the C1PrintPreviewControl, add a C1PrintPreviewControl to the form, and complete the following steps:

    1. Click once on the C1PrintPreview control on the form to select it, and navigate to the Properties window.
    2. In the Properties window, locate and expand the Toolbars top-level property by clicking on the plus sign (+) to the left of the item. You should see the list of predefined preview toolbars: File, Navigation, Page, Text, and Zoom.
    3. Select and expand the toolbar, for instance File, that will contain the new item. The expanded list should show the predefined File buttons: Open, PageSetup, Print, Reflow, Save, and a ToolStrip expandable item.
    4. Select and expand the ToolStrip item. The expanded list should contain a single Items collection node.
    5. Select the Items node and click on the ellipses (...) button to the right of the item. The items collection editor dialog box containing the predefined items will be displayed.
    6. Add a new button using the collection dialog box's commands, adjust its properties as needed, note the name of the button, and press OK to close the dialog box and save the changes. Now you should see the newly added button in the designer view.
    7. Select the newly added button in the Properties window (you can do this by either clicking on the button in the designer view, or by selecting the button by its name from the Properties window's drop-down list).

    Once you have added the toolbar button, you can customize its actions. You can now add a Click event handler to the button or further customize its properties.

    Tip 2: Change the Default Toolbar Button Processing

    To change the default processing of a built-in toolbar button on a C1PrintPreviewControl, you need to handle the preview pane's UserAction event.

    Add a C1PrintPreviewControl to the form, and complete the following steps:

    1. Click on the preview pane within that control (the main area showing the pages of the viewed document) in the Visual Studio designer.
    2. This will select the C1PreviewPane within the preview control into the properties window. For example, if your preview control has the name c1PrintPreviewControl1, the selected object's name should become c1PrintPreviewControl1.PreviewPane.
    3. Click the lightning bolt icon in the Properties window to view Events, scroll to the UserAction event item, and double click the item to create an event handler.
    4. You can customize the default processing of a built-in toolbar button in the UserAction event handler.

    The handler receives an instance of UserActionEventArgs which contains two interesting properties: PreviewAction and Cancel. PreviewAction is an enum listing all supported user events, such as file open, print, and so on. Testing that property you may find the action you're interested in. The other important property of UserActionEventArgs is Cancel - if you add your own processing to an action and want to omit the standard processing, set UserActionEventArgs.Cancel to True, otherwise standard processing will take place after your event handler returns.

    Tip 3: Using Preview Pane's PropertyChanged Event

    To monitor interesting preview related properties, use the PropertyChanged event on the C1PreviewPane object within the C1PrintPreviewControl. All of the preview pane's own properties (not inherited from its base control) fire the PropertyChanged event when their values change.

    For instance, the following code will add a handler to the PropertyChanged event provided that your form includes a C1PrintPreviewControl named c1PreviewControl1:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    AddHandler Me.C1PrintPreviewControl1.PreviewPane.PropertyChanged, AddressOf PreviewPane_PropertyChanged

    To write code in C#

    C#
    Copy Code
    this.c1PrintPreviewControl1.PreviewPane.PropertyChanged += new PropertyChangedEventHandler(PreviewPane_PropertyChanged);

    The following property changed event handler will print a debug line each time the current page changes in the preview for whatever reason:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub PreviewPane_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)    
        If e.PropertyName = "StartPageIdx" Then    
            Debug.WriteLine("Current page changed to " & Me.c1PrintPreviewControl1.PreviewPane.StartPageIdx.ToString())    
        End If    
    End Sub
    

    To write code in C#

    C#
    Copy Code
    void PreviewPane_PropertyChanged(object sender, PropertyChangedEventArgs e)    
    {    
      if (e.PropertyName == "StartPageIdx")    
        Debug.WriteLine("Current page changed to " + this.c1PrintPreviewControl1.PreviewPane.StartPageIdx.ToString());    
    }