用户经常需要更改工具栏的外观或自定义导出菜单,但并不是每个人都知道如何做到这一点。假设我们已经有一个完成的项目。例如,我们可以使用来自 FastReport .NET 演示应用程序的任何 告。
表生成器
用户经常需要更改工具栏的外观或自定义导出菜单,但并不是每个人都知道如何做到这一点。假设我们已经有一个完成的项目。例如,我们可以使用来自 FastReport .NET 演示应用程序的任何 告。
让我们为工具栏添加一些颜色。我们需要编写一段代码来负责定制:
ToolbarSettings toolbar = new ToolbarSettings(){ Color = Color.Red, DropDownMenuColor = Color.IndianRed, IconColor = IconColors.Left, Position = Positions.Left, IconTransparency = IconTransparencyEnum.Low,};webReport.Toolbar = toolbar;
现在让我们运行我们的应用程序,看看结果

让我们更详细地看看FastReport Web for Core中工具栏的定制是如何进行的。
所有的自定义参数都被存储为一个属性集合。有几个选项可以让你实现对工具栏外观的改变,但它们都归结为添加或改变参数。
让我们从代码中考虑外观定制,在这里你可以看到一个集合和属性的列表。下面是其中的一些。
- Color – 改变工具栏的背景颜色。
- DropDownMenuColor – 设置下拉菜单的背景颜色。
- DropDownMenuTextColor – 设置下拉菜单的文本颜色。
- Position – 改变工具条在 告中的位置。
- Roundness – 为工具条添加圆度。
- ContentPosition – 改变内容的位置。
- IconColor – 改变图标的颜色。
- IconTransparency – 调整图标的透明度。
- FontSettings – 微调文本样式。
让我们假设我们想改变下拉菜单的颜色,并在其中显示各种出口选项。
要改变下拉菜单的外观,你只需要在工具栏中写一些修改。但是要显示所有的导出数据选项,你需要添加下面这段代码。
ToolbarSettings toolbar = new ToolbarSettings() { Color = Color.Red, DropDownMenuColor = Color.Red, DropDownMenuTextColor = Color.White, IconColor = IconColors.White, Position = Positions.Right, FontSettings = new Font("Arial", 14, FontStyle.Bold), Exports = new ExportMenuSettings() { ExportTypes = Exports.All } }; model.WebReport.Toolbar = toolbar;
如果我们运行我们的项目,我们会看到下拉菜单已经改变,导出数据的选项明显增加。

现在我们看到一个带有导出格式的自定义菜单。
但如果我们只需要某些格式呢如,我们只需要PDF,XPS,和CSV。让我们来实现它吧!
我们需要稍微改变容器中的导出设置。
Exports = new ExportMenuSettings(){ ExportTypes = Exports.Pdf | Exports.Xps | Exports.Csv}
让我们运行我们的应用程序,看看结果。

如果只显示这些导出选项,那么你就做对了一切。
在Blazor中定制对象的外观
我们还需要提到Blazor,它包括普通版本的所有功能,但有更高级的功能。
我们将使用下面文章中的项目。Blazor中的 告和PDF文档。
让我们来定制工具栏的外观。
转到Pages/Index.razor.cs文件。在这里,我们将自定义工具栏,并添加负责在Blazor中进行自定义的部分代码。
var toolbar = new ToolbarSettings{ FontSettings = new Font("Verdana,Arial sans-serif", 15), Color = Color.Red, DropDownMenuColor = Color.Red, DropDownMenuTextColor = Color.White, IconColor = IconColors.White, Position = Positions.Bottom, ContentPosition = ContentPositions.Center,};

想象一下,除了简单的定制之外,我们还需要增加导出到PS、HPGL、JSON和PDF。
让我们添加以下代码来实现这一点。
Exports = new ExportMenuSettings(){ ExportTypes = Exports.PS | Exports.Hpgl | Exports.Json | Exports.Pdf}
因此,我们将得到我们需要的出口设置。

目前,Index.razor和Index.razor.cs文件看起来像这样。
@page "/"@page "/{ReportName}"@inject NavigationManager NavManager<WebReportContainer WebReport="@UserWebReport" >@code { [Parameter] public string ReportName { get; set; } protected override void OnParametersSet() { base.OnParametersSet(); Load(); }}
using System;using System.Drawing;using System.IO;using FastReport;using FastReport.Web;using System.Data;namespace Blazor.UserDebugApp.Pages{ public partial class Index { private readonly string directory; private const string DEFAULT_REPORT = "Simple List.frx"; public WebReport UserWebReport { get; set; } Report Report { get; set; } DataSet DataSet { get; } ToolbarSettings Toolbar { get; } public Index() { directory = Path.Combine( Directory.GetCurrentDirectory(), Path.Combine("..", "Demos", "Reports")); DataSet = new DataSet(); DataSet.ReadXml(Path.Combine(directory, "nwind.xml")); Toolbar = new ToolbarSettings { FontSettings = new Font("Verdana,Arial sans-serif", 15), Color = Color.Red, DropDownMenuColor = Color.Red, DropDownMenuTextColor = Color.White, IconColor = IconColors.White, Position = Positions.Bottom, ContentPosition = ContentPositions.Center, Exports = new ExportMenuSettings() { ExportTypes=Exports.PS|Exports.Hpgl|Exports.Json|Exports.Pdf } }; } private void Load() { Report = Report.FromFile( Path.Combine( directory, string.IsNullOrEmpty(ReportName) DEFAULT_REPORT : ReportName)); Report.RegisterData(DataSet, "NorthWind"); UserWebReport = new WebReport(); UserWebReport.Report = Report; UserWebReport.Toolbar = Toolbar; } }}
Fastreport.NET在线购买价更低!赶紧加入购物清单吧!
如果您有任何疑问或需求,请随时加入FastReport技术交流群(702295239),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!