CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008
    Posts
    136

    Thumbs up How to insert barcode images into the Header or Footer sections of a RDLC ReportViewe

    How to insert barcode images into the Header or Footer sections of a RDLC ReportViewer in Windows Forms with C# or VB

    Prerequisites
    - Neodynamic Barcode Professional 7.0 for .NET Windows Forms (or greater)
    - Microsoft .NET Framework 3.5 (or greater)
    - Microsoft Visual Studio 2010 or Visual Basic 2010 Express or Visual C# 2010 Express

    In this simple guide you will learn how to insert a barcode image to the Header or Footer sections of a RDLC report in a Windows Forms application project using C# or VB.NET and Neodynamic Barcode Professional for Windows Forms.
    RDLC reports are included since Visual Studio 2005 and allow you to design reports in Visual Studio which are displayed on a form by using ReportViewer controls.

    NOTE:
    - The source code in this guide was made by using Visual Studio 2010 but you can easily use it in older versions of ReportViewer controls like the ones delivered with Visual Studio 2008.
    - The RDLC report in this guide has no data source settings for simplicity but the same technique shows here can be used with reports bound to any data source.

    The idea is to create a Windows form allowing the user to enter a text value which will be converted to a barcode images inserting it in the Header section of a RDLC report. In this guide we'll generate a well known linear barcode called Code 128 (USS Code 128) using Neodynamic Barcode Professional for Windows Forms component based on the specified value but you could use any of the barcode standards included in Barcode Professional like Code 39, EAN-13, UPC-A, GS1-128, USPS Intelligent Mail Barcode as well as 2D symbologies like Data Matrix, QR Code, Aztec Code, PDF 417, etc. (More info about all supported barcode symbologies in Barcode Pro for Windows Forms)

    http://www.neodynamic.com/demo-faq/b...DLC-report.jpg
    The Windows Forms app sample displaying a barcode image inside the Header section of a RDLC report


    Please follow up these steps:
    - Download and install latest version of Neodynamic Barcode Professional for Windows Forms .NET
    - Open Visual Studio and create a new Windows Forms application naming it LocalReportWithBarcodeInHeader
    - Add a new RDLC Report item to your project
    - With the report displayed at design time, click Report > Report Properties
    In the Report Properties dialog box, click Code tab and enter the following function. Then click OK

    Public Function GetBarcodeImageHeader(ByVal barcodebase64 As String) As Byte()
    Return Convert.FromBase64String(barcodebase64)
    End Function

    - Add a new parameter to the report naming it BarcodeBinaryContent and the data type for it must be set up to Text
    - With the report displayed at design time, click Report > Add Page Header
    - Design your report so it looks like the following figure. In it, the main element is the Image control which will be used to display the barcode image generated by Barcode Professional

    http://www.neodynamic.com/demo-faq/b...ode-header.jpg

    - Select the Image control on the report and in the Properties Window set the following properties:
    -- MIMEType to image/png
    -- Source to Database
    -- Value to =Code.GetBarcodeImageHeader(Parameters!BarcodeBinaryContent.Value)
    -- Sizing to AutoSize

    - Add a reference to Neodynamic.WinControls.BarcodeProfessional.dll clicking Project > Add Reference...
    - Open the form at design time and add a Label, a TextBox, a Button and a ReportViewer control as shown in the following figure:

    http://www.neodynamic.com/demo-faq/b...ode-header.jpg

    - On the ReportViewer control and set up the RDLC report created above to it
    - Open the form's code behind class and add this method inside it:

    Visual Basic .NET
    Private Sub UpdateBarcodeOnHeader()

    If (Me.textBox1.Text.Trim = "") Then
    MessageBox.Show("Please enter a value to encode, thanks!")
    Return
    End If

    Dim barcodeBase64 As String = ""

    'Create an instance of Barcode Professional
    Using bcp As New Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional()
    'Barcode settings
    bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128
    bcp.BarcodeUnit = Neodynamic.WinControls.BarcodeProfessional.BarcodeUnit.Inch
    bcp.BarWidth = 1.0F / 96.0F
    bcp.BarHeight = 0.5F

    'Set the value to encode
    bcp.Code = Me.textBox1.Text
    'Generate the barcode image and convert to base64 string
    barcodeBase64 = Convert.ToBase64String(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png))
    End Using

    'Set report parameter
    Dim param As New Microsoft.Reporting.WinForms.ReportParameter("BarcodeBinaryContent", barcodeBase64, False)
    Me.ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WinForms.ReportParameter() {param})
    Me.ReportViewer1.RefreshReport()

    End Sub

    C#
    private void UpdateBarcodeOnHeader()
    {

    if (this.textBox1.Text.Trim() == "")
    {
    MessageBox.Show("Please enter a value to encode, thanks!");
    return;
    }

    string barcodeBase64 = "";

    //Create an instance of Barcode Professional
    using (Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional())
    {
    //Barcode settings
    bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128;
    bcp.BarcodeUnit = Neodynamic.WinControls.BarcodeProfessional.BarcodeUnit.Inch;
    bcp.BarWidth = 1f / 96f;
    bcp.BarHeight = 0.5f;

    //Set the value to encode
    bcp.Code = this.textBox1.Text;
    //Generate the barcode image and convert to base64 string
    barcodeBase64 = Convert.ToBase64String(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png));
    }

    //Set report parameter
    Microsoft.Reporting.WinForms.ReportParameter param = new Microsoft.Reporting.WinForms.ReportParameter("BarcodeBinaryContent", barcodeBase64, false);
    this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] { param });

    this.reportViewer1.RefreshReport();
    }


    - Add this code to the Form_Load event handler:

    Visual Basic .NET
    Me.textBox1.Text = "000111222333"

    UpdateBarcodeOnHeader()

    C#
    this.textBox1.Text = "000111222333";

    UpdateBarcodeOnHeader();

    - On the form, double click on the button and add this code to the Click event handler:

    Visual Basic .NET
    UpdateBarcodeOnHeader()

    C#
    UpdateBarcodeOnHeader();

    - That's it. Run the project. Enter some value to encode and click on Refresh button so the barcode on the report's header be updated.


    Links:
    This Demo
    More Demos
    Download Barcode Professional for Windows Forms
    More Information about Neodynamic Barcode Professional for Windows Forms

    Neodynamic
    .NET Components & Controls
    http://www.neodynamic.com
    http://www.barcode-for-net.com

  2. #2
    Join Date
    Apr 2013
    Posts
    1

    Re: How to insert barcode images into the Header or Footer sections of a RDLC ReportV

    This article was superb,can any body help me out how to display a pdf file in the footer of the rdlc in the windows application and the footer has to be displayed only once.For example if the rdlc has 3 pages then footer has to be displayed with pdf(if not possible,let it be with the image) on the third page.Thanks in advance.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured