原創(chuàng)|行業(yè)資訊|編輯:何家巧|2022-12-29 15:33:27.590|閱讀 297 次
概述:在使用報(bào)表開(kāi)發(fā)工具FastReport.NET的過(guò)程中,總會(huì)遇見(jiàn)授權(quán)或者使用問(wèn)題,今天我們就聯(lián)合廠商為大家?guī)?lái)五個(gè)常見(jiàn)問(wèn)題的解答,希望能夠幫到大家。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
相關(guān)鏈接:
Fastreport是目前世界上主流的圖表控件,具有超高性價(jià)比,以更具成本優(yōu)勢(shì)的價(jià)格,便能提供功能齊全的報(bào)表解決方案,連續(xù)三年蟬聯(lián)全球文檔創(chuàng)建組件和庫(kù)的“ Top 50 Publishers”獎(jiǎng)。慧都科技是Fast Reports在中國(guó)區(qū)十余年的友好合作伙伴,連續(xù)多年被Fast Reports授予中國(guó)區(qū)Best Partner稱號(hào)。
上一篇我們了解到了在使用FastReport .Net十大常見(jiàn)問(wèn)題及解決辦法,今天我們繼續(xù)討論常常遇到的5個(gè)問(wèn)題及解決方法。
問(wèn)題1:如何從代碼繼承報(bào)告?
1.需要您創(chuàng)建新報(bào)告:
Report report = new Report();
2.添加 CustomLoadEventHandler 加載基礎(chǔ)報(bào)表:
report.LoadBaseReport += new CustomLoadEventHandler(FReport_LoadBaseReport);
3.加載繼承報(bào)表:
report.Load("InheritReport.frx");
4.刪除CustomLoadEventHandler:
report.LoadBaseReport -= new CustomLoadEventHandler(FReport_LoadBaseReport);
5.您可以顯示報(bào)告或編輯報(bào)告,報(bào)告有基礎(chǔ)報(bào)告和繼承報(bào)告:
report.Show();
同時(shí)還需要?jiǎng)?chuàng)建加載基礎(chǔ)報(bào)告的事件:
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");
}
}
如果要從數(shù)據(jù)庫(kù)加載報(bào)告,請(qǐng)?zhí)鎿Q LoadFromString() 上的 Load() 方法。
問(wèn)題2:如何刪除最終用戶的代碼選項(xiàng)卡?
environmentSettings1.DesignerSettings.Restrictions.DontEditCode = true;
這樣數(shù)據(jù)控件將被禁用。2) 將 WindowsFormsHost 標(biāo)記添加到您的 XAML 標(biāo)記中:
<WindowsFormsHost Horizo ntalAlignment = "Stretch" VerticalAlignment = "Stretch" Grid.Column = "0" Grid.ColumnSpan = "3" >
</WindowsFormsHost >
3) 將子項(xiàng)添加到 WindowsFormsHost 中:<fr:PreviewControl></fr:PreviewControl> 或 <fr1:Designer></fr1:Designer>。完整標(biāo)記應(yīng)類似于以下代碼段:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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>
問(wèn)題4:如何以編程方式設(shè)置格式的值
您可以使用以下代碼在腳本或項(xiàng)目中執(zhí)行此操作:
FastReport.Format.NumberFormat format = new FastReport.Format.NumberFormat();
format.UseLocale = false;
format.DecimalDigits = 2;
format.DecimalSeparator = ".";
format.GroupSeparator = ",";
接下來(lái):
textObject.Formats.Clear();
textObject.Formats.Add(format);
問(wèn)題5:如何在MSChartObject中創(chuàng)建一條有間隙的線?
您應(yīng)該創(chuàng)建基礎(chǔ) System.Windows.Forms.DataVisualization.Charting.Series 對(duì)象并在那里創(chuàng)建行。在此之后應(yīng)該為 MSChartObject 基本圖表分配創(chuàng)建的系列(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);
}
}
}
關(guān)于“FastReport .NET五大常見(jiàn)問(wèn)題”的講解就到這里了,點(diǎn)擊查看上一章:FastReport .Nets十大常見(jiàn)問(wèn)題及解決辦法。
如您有更多相關(guān)問(wèn)題,歡迎加入官方技術(shù)群交流解決。
FastReport技術(shù)QQ群:536197826 歡迎進(jìn)群一起討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn