Adding Components c# FAIL

Stimulsoft Reports.WPF discussion
Post Reply
DeSchneller
Posts: 12
Joined: Mon Oct 31, 2011 4:58 am
Location: Germany

Adding Components c# FAIL

Post by DeSchneller »

Hi there,

I tried to test creating an report by c#-Code.

Code: Select all

using System;
using System.Drawing;
using System.Drawing.Text;
using System.Windows;
using Stimulsoft.Base.Drawing;
using Stimulsoft.Report;
using Stimulsoft.Report.Components;
using Stimulsoft.Report.Events;

namespace ReportTest
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            StiReport report = new StiReport
            {
                ReportName = "ZV",
                ReportCreated = DateTime.Now,
                ReportUnit = StiReportUnitType.Millimeters,
                ScriptLanguage = StiReportLanguageType.CSharp
            };

            StiPage page = new StiPage
            {
                Name = "Page1",
                Height = 297,
                Width = 210,
                Guid = new Guid().ToString(),
                Border =
                    new StiBorder(StiBorderSides.None, Color.Black, 4, StiPenStyle.Solid, false, 4,
                        new StiSolidBrush(Color.Black), false),
                Brush = new StiSolidBrush(Color.Transparent),
                ExcelSheetValue = null,
                Margins = new StiMargins(1, 1, 1, 1),
                Report = report
            };

            StiText header = new StiText
            {
                Name = "HeaderText",
                ClientRectangle = new RectangleD(new PointD(22.5, 18), new SizeD(152.5, 6)),
                HorAlignment = StiTextHorAlignment.Left,
                VertAlignment = StiVertAlignment.Center,
                Type = StiSystemTextType.Expression,
                Font = new Font("Arial", 13f, System.Drawing.FontStyle.Bold),
                Margins = new StiMargins(0, 0, 0, 0),
                TextBrush = new StiSolidBrush(Color.Black),
                TextOptions = new StiTextOptions(false, false, true, 0f, HotkeyPrefix.None, StringTrimming.Word),
                Page = page,
                Parent = page,
                Printable = true,
                PrintOn = StiPrintOnType.AllPages,
                Border =
                    new StiBorder(StiBorderSides.None, Color.Black, 1, StiPenStyle.Solid, false, 4,
                        new StiSolidBrush(Color.Black), false),
                Brush = new StiSolidBrush(Color.Transparent),
                Guid = null,
                Indicator = null,
                Interaction = null
            };

            header.GetValue += new StiGetValueEventHandler(GetHeaderTextValue);

            page.Components.AddRange(new StiComponent[] {header});

            report.Pages.Clear();
            report.Pages.AddRange(new StiPage[] {page});

            report.Render(true);

            stiWpfViewerControl1.Report = report;
        }

        private void GetHeaderTextValue(object sender, StiGetValueEventArgs e)
        {
            e.Value = "Vollstreckungsauftrag an die Ferichtsvollzieherin/den Gerichtsvollzieher";
        }
    }
}
The Problem is that the Report only shows the Page but not ne Text i tried to insert.

Thanks for help.
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Adding Components c# FAIL

Post by HighAley »

Hello.

The problem is that you add the event to the component of the not compiled report.
But we don't pass them to the compiled report.

We can suggest you next solutions:

1. You could compile the report and add the event there

2. Add the event as a script. For example:

Code: Select all

StiText header = new StiText
{
    Name = "HeaderText",
    GetValueEvent = new Stimulsoft.Report.Events.StiGetValueEvent("e.Value = \"Vollstreckungsauftrag an die Ferichtsvollzieherin/den Gerichtsvollzieher\";"),
    ClientRectangle = new RectangleD(new PointD(22.5, 18), new SizeD(152.5, 6)),
     ........
};
Thank you.
Post Reply