The following tips relate to the visual previewing controls included in Reports for WinForms (such as C1PrintPreviewControl, C1PrintPreviewDialog, C1PreviewPane, C1PreviewThumbnailView, C1PreviewOutlineView, and C1PreviewTextSearchPanel).
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:
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.
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:
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.
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()); } |