报表开发工具FastReport.NET的五大常见问题及解决方法

在使用报表开发工具FastReport.NET的过程中,总会遇见授权或者使用问题,今天我们就联合厂商为大家带来五个常见问题的解答,希望能够帮到大家。

上一篇我们了解到了在使用FastReport .Net十大常见问题及解决办法,今天我们继续讨论常常遇到的5个问题及解决方法。

问题1:如何从代码继承报告/span>

1.需要您创建新报告:

Report report = new Report();

2.添加 CustomLoadEventHandler 加载基础报表:

report.LoadBaseReport += new CustomLoadEventHandler(FReport_LoadBaseReport); 

3.加载继承报表:

report.Load("InheritReport.frx"); 

4.删除CustomLoadEventHandler:

report.LoadBaseReport -= new CustomLoadEventHandler(FReport_LoadBaseReport); 

5.您可以显示报告或编辑报告,报告有基础报告和继承报告:

report.Show(); 

同时还需要创建加载基础报告的事件:

private void FReport_LoadBaseReport(object sender, CustomLoadEventArgs e) { // e.FileName contains the name of base report. It may be the file name, or an ID in the database, // it depends on how you load the main report e.Report.Load("C:\Users\InheritReport\bin\Debug\Title2.frx"); }  

完整的代码

public partial class Form1 : Form { public Form1() { InitializeComponent(); }  private void Form1_Load(object sender, EventArgs e) { Report report = new Report(); report.LoadBaseReport += new CustomLoadEventHandler(FReport_LoadBaseReport); report.Load("InheritReport.frx"); report.LoadBaseReport -= new CustomLoadEventHandler(FReport_LoadBaseReport);  report.Show(); }  private void FReport_LoadBaseReport(object sender, CustomLoadEventArgs e) { // e.FileName contains the name of base report. It may be the file name, or an ID in the database, // it depends on how you load the main report e.Report.Load("C:\Users\InheritReport\bin\Debug\Title2.frx"); } }

如果要从数据库加载报告,请替换 LoadFromString() 上的 Load() 方法。

问题2:如何删除最终用户的代码选项卡/strong>
将“EnvironmentSettings”控件添加到您的表单。 
然后在调用 report.Design() 之前添加以下行:

environmentSettings1.DesignerSettings.Restrictions.DontEditCode = true;

这样数据控件将被禁用。
问题3:如何在WPF应用程序中使用FastReport.Net控件/strong>
您应该为它使用 WindowsFormsHost 控件:
0) 添加对FastReport.dll的引用;
1) 添加属性到Window(Page) 标签: xmlns_fr=”clr-namespace:FastReport.Preview;assembly=FastReport” 如果你想使用PreviewControl, xmlns_fr1=”clr-namespace:FastReport.Design;assembly= FastReport” – 如果是 DesignerControl;

2) 将 WindowsFormsHost 标记添加到您的 XAML 标记中:

<WindowsFormsHost  Horizo ntalAlignment = "Stretch"  VerticalAlignment = "Stretch"  Grid.Column = "0"  Grid.ColumnSpan = "3" > </WindowsFormsHost > 

3) 将子项添加到 WindowsFormsHost 中:<fr:PreviewControl></fr:PreviewControl> 或 <fr1:Designer></fr1:Designer>。

完整标记应类似于以下代码段:

<Window  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  x:Class="WpfApplication1.MainWindow" Title="MainWindow" Height="375.977" Width="939.258" xmlns:fr="clr-namespace:FastReport.Preview;assembly=FastReport"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <WindowsFormsHost HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.ColumnSpan="3"> <fr:PreviewControl></fr:PreviewControl> </WindowsFormsHost> </Grid></Window>

问题4:如何以编程方式设置格式的值
您可以使用以下代码在脚本或项目中执行此操作:

FastReport.Format.NumberFormat format = new FastReport.Format.NumberFormat();format.UseLocale = false;format.DecimalDigits = 2;format.DecimalSeparator = ".";format.GroupSeparator = ","; 

接下来:

textObject.Formats.Clear();textObject.Formats.Add(format); 

问题5:如何在MSChartObject中创建一条有间隙的线/strong>
您应该创建基础 System.Windows.Forms.DataVisualization.Charting.Series 对象并在那里创建行。在此之后应该为 MSChartObject 基本图表分配创建的系列(MSChart1.Chart.Series.Add(系列);)不要忘记 在 Report -> Script 菜单和命名空间 System.Windows.Forms 中添加 System.Windows.Forms.DataVisualization.dll .DataVisualization.Charting。
带间隙的线示例:

..using System.Windows.Forms.DataVisualization.Charting; namespace FastReport{ public class ReportScript { private void MSChart1_BeforePrint(object sender, EventArgs e) {  Series series = new Series("sample"); series.ChartType = SeriesChartType.Line; series.BorderWidth = 2; series.MarkerSize = 5;  series.Points.Add(new DataPoint(0, 1)); series.Points.Add(new DataPoint(1, 2)); DataPoint dp = new DataPoint(2, double.NaN); dp.IsEmpty = true; series.Points.Add(dp); series.Points.Add(new DataPoint(3, 5)); series.Points.Add(new DataPoint(4, 8));   MSChart1.Chart.Series.Add(series);  } }}

关于“FastReport .NET五大常见问题的讲解就到这里了,点击查看上一章:FastReport .Nets十大常见问题及解决办法。

如您有更多相关问题,欢迎加入官方技术群交流解决。

FastReport .Net | 下载试用

FastReport技术

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年11月26日
下一篇 2022年11月27日

相关推荐

发表回复

登录后才能评论