cancel
Showing results for 
Search instead for 
Did you mean: 

How to create own button in CrystalReportViewer1?

Former Member
0 Kudos

How to create own button in CrystalReportViewer1?

I did created button, but when I run the report it doesn’t
show up. I am Vb 2008 and CrystalReport 8

I have two forms main and report. Report review works and
prints fine. I need to update in SQL if report is printed on which date.

 

I try this:

 

'find the print button
control and attach an event to it

For Each Obj As Object In myToolStrip.Items

If TypeOf Obj Is ToolStripButton Then

'Adding a handler for our propose

Dim b As ToolStripButton = CType(Obj, ToolStripButton)

If b.ToolTipText = "Print Report" Then

AddHandler CType(Obj, ToolStripButton).Click, AddressOf printButton_Click

End If

End If
Next

 

It never went to PrintButton_Click.

Now, I created
button name is PrintButton, but PrintButton doesn’t show up in
CrystalReportViewer1

Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As system.EventArgs) Handles PrintButton.Click

Dim dialog As New PrintDialog

dialog.UseEXDialog = True

dialog.AllowSomePages = True

If dialog.ShowDialog() = DialogResult.OK Then

Dim objRpt As ReportDocument = CType(Me.CrystalReportViewer1.ReportSource,
ReportDocument)

objRpt.PrintOptions.PrinterName = dialog.PrinterSettings.PrinterName

objRpt.PrintToPrinter(1, False, 0, 0)

PrintedDate()

Else

MessageBox.Show("print cancel")

Return

End If

End Sub

Can anyone out there help me Please?
I have been trying for two months.

Thank you

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Hello Sunny

See if the following code snippet will help:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Drawing.Printing;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        CrystalReport1 cr;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ToolStrip ts;
            ts = (ToolStrip)crystalReportViewer1 .Controls[3];

            ToolStripButton printbutton = new ToolStripButton();
            printbutton.Image = ts.Items[1].Image;
            ts.Items.Remove(ts.Items[1]);
            ts.Items.Insert(1, printbutton);

            ts.Items[1].Click += new EventHandler(this.CaptureEvent);                  
            cr = new CrystalReport1();
            this.crystalReportViewer1.ReportSource = cr;
                         
        }

        private void CaptureEvent(Object Sender, EventArgs e)
        {
            try
            {        // Create a Print Dialog                
                PrintDialog printDialog1 = new PrintDialog();

                // Create a Print Document
                PrintDocument pd = new PrintDocument();

                printDialog1.Document = pd;
                printDialog1.ShowNetwork = true;
                printDialog1.AllowSomePages = true;

                DialogResult result = printDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    MessageBox.Show("Print button has been selected !!!");
                    PrintReport(printDialog1.PrinterSettings.PrinterName);
                }
                else if (result == DialogResult.Cancel)
                {
                    MessageBox.Show("Cancel button has been selected !!!");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
         }


        private void PrintReport(string printerName)
        {
            // Select the printer.
            cr.PrintOptions.PrinterName = printerName;

            /* Print the report. Set the startPageN and endPageN
             parameters to 0 to print all pages.*/
            cr.PrintToPrinter(1, false, 0, 0);
        }                         
    }
}

Also see:

1493592 How to create customized export options button for Crystal Reports winform viewer in Visual Studio ....
1400899 How to customize the viewer options for a Crystal Reports .NET Viewer

- Ludek

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Share Your Knowledge in SCN Topic Spaces

Former Member
0 Kudos

Hi Ludek,

both links do not work.

do you have code in VB.net with less modifiy?

i am new bee. help me

thanks

former_member183750
Active Contributor
0 Kudos

Content for 1493592:

Symptom


Clicking on the Export button of the viewer a choice of export formats is presented
The default export file format is an .rpt file
How to make the default export file format different?
How to remove certain export formats?


Resolution


Symptom


Clicking on the Export button of the viewer a choice of export formats is presented
The default export file format is an .rpt file
How to make the default export file format different?
How to remove certain export formats?


Resolution
Remove the viewer Export button from the toolstrip
Add a new Export button
On click event of the new Export button, present the user with custom export form
Use the following sample code


Private Sub frmReportPreview_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim ts As ToolStrip
        Dim currentExportButton As ToolStripButton
        Dim newExportButton As ToolStripButton

        ' Replace the export button with our own export button so we can handle the event ourselves
        ts = DirectCast(CRViewer.Controls(4), ToolStrip)
        currentExportButton = DirectCast(ts.Items(0), ToolStripButton)
        ts.Items.Remove(currentExportButton)
        newExportButton = New ToolStripButton("", My.Resources.Export, AddressOf ExportButton_Click)
        newExportButton.ToolTipText = "Export report to disk"
        ts.Items.Insert(0, newExportButton)

    End SubCreate windows form 'frmReportExport' that contains the export file types and their order, then use the following code:
Private Sub ExportButton_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim frmExport As frmReportExport

        ' Allow the user to specify options such as the name of the file and format before exporting.
        frmExport = New frmReportExport
        frmExport.Report = Report
        frmExport.ShowDialog()

    End SubThen use the code below to run the export from the custom report export windows form.
Report.ExportToDisk(exportFormat, fileExport.SelectedFilename)

former_member183750
Active Contributor
0 Kudos

Content for 1400899:

Symptom

A Microsoft Visual Studio .NET application uses the Crystal Reports for .NET SDK as the reporting development tool.

How do you customize the viewer options that appear in the Crystal Reports .NET Forms Viewer?

Resolution

The following properties can be set to change the Crystal Reports Viewer options:

ShowCloseButton, ShowExportButton, ShowGotoPageButon, ShowGroupTreeButton, ShowPageNavigateButton, ShowParameterPanelButton, ShowPrintButton, ShowRefreshButton, ShowTextSearchButton , ShowZoomButton

If these properties are set to true the buttons will appear on the viewer toolbar.
If additional or replacement functionality is required, set the appropriate button property to false to hide the button and place an additional element on the viewer.
It is not possible to extend the viewer toolbar.

former_member183750
Active Contributor
0 Kudos

Re.:

do you have code in VB.net with less modifiy?

No I do not.

- Ludek

Former Member
0 Kudos

how do you place an additional element on the viewer?

i know you can put true or false on these buttons:  ShowCloseButton, ShowExportButton, ShowGotoPageButon, ShowGroupTreeButton, ShowPageNavigateButton, ShowParameterPanelButton, ShowPrintButton, ShowRefreshButton, ShowTextSearchButton , ShowZoomButton

former_member183750
Active Contributor
0 Kudos

Define "additional element"(?).

- Ludek

Former Member
0 Kudos

Hi Ludek,

Your told me in your last posting (Ludek Uher

“place an additional element on the viewer. It is not possible to extend the viewer toolbar.”

any help or your are waste of time?

you can email at sunny_caar@yahoo.com this is what I am trying to do

I created a report using vb.net 2008 and crystal report viewer. If user print the report, I need to record it. User click on print icon and print dialog show up with default print then user can click print or cancel. When the user clicks on the Print button on the Print Dialog, I want to create an event on it so that I can record the printing transaction. Any help is highly appreciated. Thank you!
former_member183750
Active Contributor
0 Kudos

Does the code I gave on April 2nd not help?

- Ludek

Answers (0)