-
Notifications
You must be signed in to change notification settings - Fork 204
WinForms Viewer
Peter Gill edited this page Jun 8, 2026
·
2 revisions
dotnet add package Majorsilence.Reporting.RdlViewerLoad a report and display it. Call RdlEngineConfig.RdlEngineConfigInit() once at startup, then use SetSourceFile and Rebuild (both async) in the form's Load event.
using System.Windows.Forms;
using Majorsilence.Reporting.Rdl;
using Majorsilence.Reporting.RdlViewer;
class ReportForm : Form
{
private readonly RdlViewer _rdlView;
public ReportForm()
{
Height = 600;
Width = 800;
_rdlView = new RdlViewer { Dock = DockStyle.Fill };
Controls.Add(_rdlView);
Load += async (s, e) => await LoadReportAsync();
}
private async Task LoadReportAsync()
{
await _rdlView.SetSourceFile(new Uri(@"C:\reports\report.rdl"));
await _rdlView.Rebuild();
}
}
class Program
{
[STAThread]
static void Main()
{
RdlEngineConfig.RdlEngineConfigInit();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ReportForm());
}
}Set Parameters before calling Rebuild. The format is an ampersand-separated name=value string with a leading &.
private async Task LoadReportAsync()
{
await _rdlView.SetSourceFile(new Uri(@"C:\reports\report_with_parameters.rdl"));
_rdlView.Parameters += "&StartDate=2024-01-01&EndDate=2024-12-31";
await _rdlView.Rebuild();
}See Report Parameters for all parameter-passing methods including JSON and IDictionary overloads.
SaveAs exports the currently loaded report to a file without opening a save dialog:
// Export to PDF
await _rdlView.SaveAs(@"C:\output\report.pdf", OutputPresentationType.PDF);
// Export to Excel
await _rdlView.SaveAs(@"C:\output\report.xlsx", OutputPresentationType.Excel2007);
// Export to CSV
await _rdlView.SaveAs(@"C:\output\report.csv", OutputPresentationType.CSV);See Output Formats for all supported format values.
using System.Drawing.Printing;
var pd = new PrintDocument();
// Configure pd.PrinterSettings here (printer name, copies, etc.)
await _rdlView.Print(pd);// Find first occurrence of a search term and scroll to it
var item = await _rdlView.Find("quarterly revenue");
// Find the next occurrence
await _rdlView.FindNext();
// Highlight all occurrences without navigating
_rdlView.HighlightText = "quarterly revenue";
_rdlView.HighlightAll = true; // highlight every match
_rdlView.HighlightCaseSensitive = false;
await _rdlView.Rebuild();
// Scroll to a specific PageItem returned by Find
await _rdlView.ScrollToPageItem(item);// Enable text selection mode
_rdlView.SelectTool = true;
// After the user selects text, read it
string selected = _rdlView.SelectText;
// Copy to clipboard
if (_rdlView.CanCopy)
_rdlView.Copy();// Set zoom as a fraction (1.0 = 100%, 1.5 = 150%, 0.75 = 75%)
_rdlView.Zoom = 1.5f;
// Or use a named zoom mode
_rdlView.ZoomMode = ZoomEnum.FitWidth; // fit page width to window
_rdlView.ZoomMode = ZoomEnum.FitPage; // fit whole page in window
_rdlView.ZoomMode = ZoomEnum.Percent; // use Zoom property value
// Control scrollbars
_rdlView.ScrollMode = ScrollModeEnum.Auto; // show as needed
_rdlView.ScrollMode = ScrollModeEnum.Vertical; // vertical only
_rdlView.ScrollMode = ScrollModeEnum.None; // no scrollbars// Parameter input panel (appears when report has prompts)
_rdlView.ShowParameterPanel = false; // hide even if report has parameters
_rdlView.ShowParameterPanel = true; // show (default when prompts exist)
// Text search panel
_rdlView.ShowFindPanel = true;
// Run/refresh button inside the parameter panel
_rdlView.HideRunButton();
_rdlView.ShowRunButton();If the RDL is stored in a database, generated in memory, or fetched from an API, use SetSourceRdl instead of SetSourceFile:
string rdlXml = await myReportRepository.GetRdlAsync("SalesReport");
await _rdlView.SetSourceRdl(rdlXml);
await _rdlView.Rebuild();int total = _rdlView.PageCount;
int current = _rdlView.PageCurrent;
// Jump to a specific page
_rdlView.PageCurrent = 5;
await _rdlView.Rebuild();string name = _rdlView.ReportName;
string author = _rdlView.ReportAuthor;
string desc = _rdlView.ReportDescription;| Member | Type | Description |
|---|---|---|
SetSourceFile(Uri) |
async method | Load report from file |
SetSourceRdl(string) |
async method | Load report from RDL XML string |
Rebuild() |
async method | Re-render the current report |
Report() |
async method | Get the underlying Report object |
SaveAs(path, type) |
async method | Export to file |
Print(PrintDocument) |
async method | Send to printer |
Find(string) |
async method | Find first match, returns PageItem
|
FindNext() |
async method | Find next match |
ScrollToPageItem(PageItem) |
async method | Scroll to a specific item |
Copy() |
method | Copy selected text to clipboard |
HideRunButton() / ShowRunButton()
|
methods | Toggle run button visibility |
Parameters |
string property | Ampersand-separated parameter string |
SetReportParameters(IDictionary) |
method | Set parameters from dictionary |
SetReportParametersAmpersandSeparated(string) |
method | Set parameters from p=v&p2=v2 string |
SetReportParametersAsJson(string) |
method | Set parameters from JSON string |
PageCount |
int | Total page count |
PageCurrent |
int | Current page (get/set) |
Zoom |
float | Zoom level (1.0 = 100%) |
ZoomMode |
ZoomEnum | FitWidth, FitPage, Percent |
ScrollMode |
ScrollModeEnum | Auto, Both, Horizontal, Vertical, None |
ShowParameterPanel |
bool | Show/hide parameter input panel |
ShowFindPanel |
bool | Show/hide find panel |
SelectTool |
bool | Enable text selection mode |
SelectText |
string | Currently selected text |
CanCopy |
bool | True if text is selected |
HighlightText |
string | Text to highlight |
HighlightAll |
bool | Highlight all occurrences |
HighlightCaseSensitive |
bool | Case-sensitive highlight |
ReportName |
string | Report name from RDL metadata |
ReportAuthor |
string | Report author from RDL metadata |
ReportDescription |
string | Report description from RDL metadata |
using System.Windows.Forms;
using fyiReporting.RDL;
using fyiReporting.RdlViewer;
var form = new Form { Height = 600, Width = 800 };
var rdlView = new fyiReporting.RdlViewer.RdlViewer();
rdlView.SourceFile = new Uri(@"\path\to\your\report.rdl");
rdlView.Rebuild();
rdlView.Dock = DockStyle.Fill;
form.Controls.Add(rdlView);
Application.Run(form);