[]
You can customize the Print Preview settings to show the Print Preview Dialog like Excel by using the EnhancePreview property of the PrintInfo class.
The following image shows the printing options that appear on your screen after setting the EnhancePreview property to true.
Using Code
Set the EnhancePreview property of the PrintInfo class to true in order to customize the print preview setting to show the Print Preview Dialog like Excel.
This example shows how to set the EnhancePreview property.
//Code to show print preview dialog like Excel
fpSpread1.ActiveSheet.Cells[1, 1].Value = "1,1";
fpSpread1.ActiveSheet.Cells[10, 10].Value = "10,10";
fpSpread1.ActiveSheet.PrintInfo.EnhancePreview = true;
fpSpread1.PrintSheet(fpSpread1.ActiveSheet);
'Code to show print preview dialog like Excel
fpSpread1.ActiveSheet.Cells(1, 1).Value = "1,1"
fpSpread1.ActiveSheet.Cells(10, 10).Value = "10,10"
fpSpread1.ActiveSheet.PrintInfo.EnhancePreview = True
fpSpread1.PrintSheet(fpSpread1.ActiveSheet)
Spread for WinForms allows you to customize and localize the text displayed in EnhancedPrintPreview and PageSetup dialog in your preferred language. To localize these dialogs, use the FarPoint.Win.Localizer.LocalizeText event, which manages the retrieval of localized strings from a resource file. The localization of these dialogs works only when the ExcelCompatiblePrinting is true.
The localization of strings in dialogs is based on the same approach as the standard localization of .NET Winforms, which uses the resource files (.resx) to store translations.
You need to create separate resource files for each language, which allows you to switch between localized resources at runtime. It is important to ensure that all parts of the application using a particular DLL (assembly) must share the same localization resource, as it creates inconsistency if different resources are used.
The following code is used to localize the EnhancedPrintPreview and the PageSetup dialogs.
//Event that manages the retrieval of translated strings
FarPoint.Win.Localizer localizer = FarPoint.Win.Localizer.Instance;
localizer.LocalizeText += Localizer_LocalizeText;
//EnhancedPrintPreview is the name of namespace and enhancedprintpreview is the name of .resx file
enhancePrintPreviewResx = new ResourceManager("EnhancedPrintPreview.Resources.enhancedprintpreview", typeof(Resources.enhancedprintpreview).Assembly);
pageSetupResx = new ResourceManager("PrintPreview.Resources.pagesetup", typeof(Resource.pagesetup).Assembly);
private void Localizer_LocalizeText(object sender, LocalizedTextEventArgs e)
{
string text = null;
if (sender is Form)
{
string senderName = ((Form)sender).Name;
switch (senderName)
{
case "EnhancedPrintPreviewDialog":
{
text = enhancePrintPreviewResx.GetString(e.Key);
break;
}
case "PageSetup":
{
text = pageSetupResx.GetString(e.Key);
break;
}
}
}
if (text != null)
e.Text = text;
}
'Event that manages the retrieval of translated strings
Dim localizer As FarPoint.Win.Localizer = FarPoint.Win.Localizer.Instance
AddHandler localizer.LocalizeText, AddressOf Localizer_LocalizeText
'EnhancedPrintPreview is the name of namespace and enhancedprintpreview is the name of .resx file
enhancePrintPreviewResx = New ResourceManager("EnhancedPrintPreview.Resources.enhancedprintpreview", GetType(Resources.enhancedprintpreview).Assembly)
pageSetupResx = New ResourceManager("PageSetup.Resources.pagesetup", GetType(Resources.pagesetup).Assembly)
Private Sub Localizer_LocalizeText(sender As Object, e As FarPoint.Win.LocalizedTextEventArgs)
Dim text As String = Nothing
If TypeOf sender Is Form Then
Dim senderName As String = DirectCast(sender, Form).Name
Select Case senderName
Case "EnhancedPrintPreviewDialog"
text = enhancePrintPreviewResx.GetString(e.Key)
Case "PageSetup"
text = pageSetupResx.GetString(e.Key)
End Select
End If
If text IsNot Nothing Then
e.Text = text
End If
End Sub
The image below depicts the localized text of EnhancedPrintPreview and PageSetup dialogs as per the translated Japanese language strings stored in resource files.
Localized Image for EnhancedPrintPreview Dialog | Localized Image for PageSetup Dialog |
---|---|
Understanding the Printing Options
Customizing the Print Job Settings
Customizing the Printed Page Layout
Customizing the Printed Page Header or Footer