Adding a custom form to a stiReport during preview event

Stimulsoft Reports.NET discussion
Post Reply
jing
Posts: 50
Joined: Fri Jan 26, 2007 12:47 am
Location: New Zealand

Adding a custom form to a stiReport during preview event

Post by jing »

Hi,

At the moment I have a report setup dynamically by code, I have a variable called "StockCode".

I wish to know how I can link a custom form to a StiReport (user designer), so that when the user wish to "preview" the report, a custom form will popup allowing them to choose values for the variable "StockCode", so that the report will run correctly.

I need to add the form and link it to the preview event through code.

Any help will be great

thanks
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Adding a custom form to a stiReport during preview event

Post by Edward »

You can add a custom Form to the report through code in the following way:

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Stimulsoft.Report;
using Stimulsoft.Report.Components;
using Stimulsoft.Report.ReportControls;
using Stimulsoft.Base.Drawing;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public StiReport report;

        public void ButtonControl1_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show(TextBoxControl1.Text);
            //report["StockCode"] = (report["TextBoxControl1"] as StiTextBoxControl).Text;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            report = new StiReport();
            StiForm MyForm = new StiForm();

            MyForm.Name = "MyForm";
            MyForm.Size = new System.Drawing.Size(304, 232);
            MyForm.Text = "MyFormText";
            MyForm.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
            MyForm.Page = MyForm;
            MyForm.Report = report;

            // ButtonControl1
            StiButtonControl ButtonControl1 = new StiButtonControl();
            ButtonControl1.ClientRectangle = new RectangleD(88, 136, 96, 24);
            ButtonControl1.DialogResult = System.Windows.Forms.DialogResult.OK;
            ButtonControl1.Location = new System.Drawing.Point(88, 136);
            ButtonControl1.Name = "ButtonControl1";
            ButtonControl1.Size = new System.Drawing.Size(96, 24);
            ButtonControl1.Text = "My Button";
            ButtonControl1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
            ButtonControl1.Page = MyForm;
            ButtonControl1.Parent = MyForm;

            // TextBoxControl1
            StiTextBoxControl TextBoxControl1 = new StiTextBoxControl();
            TextBoxControl1.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(88, 64, 96, 20);
            TextBoxControl1.Location = new System.Drawing.Point(88, 64);
            TextBoxControl1.Name = "TextBoxControl1";
            TextBoxControl1.Size = new System.Drawing.Size(96, 20);
            TextBoxControl1.Text = "MyTextBox";
            TextBoxControl1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F);
            TextBoxControl1.Page = MyForm;
            TextBoxControl1.Parent = MyForm;

            // Add to MyForm.Components
            MyForm.Components.AddRange(new StiComponent[] {ButtonControl1,TextBoxControl1});            

            // Button Control Click Event
            //ButtonControl1.
            //ButtonControl1.Click += new System.EventHandler(ButtonControl1_Click);
            report.Pages.Add(MyForm);

            report.Compile();
            (report["ButtonControl1"] as StiButtonControl).Click += new System.EventHandler(ButtonControl1_Click);
            report.Show();
        }
    }
}
One note. You can add an event handlers to the report after the report compiling.

Thank you.
jing
Posts: 50
Joined: Fri Jan 26, 2007 12:47 am
Location: New Zealand

Adding a custom form to a stiReport during preview event

Post by jing »

Thanks very much for your reply, it was really helpful ! Although I was wanting to add the stiForm to the "Designer" rather than the preview control and I was wanting to capture the "Preview control TAB" load event in the designer, not the stand alone preview control. Nevertheless, the code gave me some great ideas :)

Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Adding a custom form to a stiReport during preview event

Post by Edward »

jing wrote:Thanks very much for your reply, it was really helpful ! Although I was wanting to add the stiForm to the "Designer" rather than the preview control and I was wanting to capture the "Preview control TAB" load event in the designer, not the stand alone preview control. Nevertheless, the code gave me some great ideas :)
Please use the static event of the StiDesigner class PreviewingReport

Thank you.
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Adding a custom form to a stiReport during preview event

Post by Brendan »

jing wrote:Thanks very much for your reply, it was really helpful ! Although I was wanting to add the stiForm to the "Designer" rather than the preview control and I was wanting to capture the "Preview control TAB" load event in the designer, not the stand alone preview control. Nevertheless, the code gave me some great ideas :)
Hi jing,
To add a Blank Form to the designer the following should work:

Code: Select all

Stimulsoft.Report.StiReport report = new Stimulsoft.Report.StiReport();
Stimulsoft.Report.ReportControls.StiForm myForm = new Stimulsoft.Report.ReportControls.StiForm(report);
myForm.Name = "Form1";
report.Pages.Add(myForm);

report.Design();
StiReport is inherited from an StiPage component so you can just add it to the Pages Collection of a Report.

Whatever controls you need to add dynamically to the Form itself afterwards can be done following Edward's helpful instructions.
Post Reply