Obtain a Label's Text in Print Preview
- 2 minutes to read
To obtain a label’s text when clicking it in Print Preview, do the following:
Create a new application or open an existing application. For more information, review the following help topic: Get Started with DevExpress Reporting.
- Add a new blank report to the application.
Drop two XRLabel controls from the DX.24.2: Report Controls Toolbox tab onto the Detail band.
To get a label’s content in Print Preview, do one of the following (depending on the target platform):
Print Preview for Windows Forms
Handle the XRControl.PreviewClick and/or XRControl.PreviewDoubleClick events of the added controls in the following way:
using System; using System.Windows.Forms; using DevExpress.XtraReports.UI; // ... private void xrLabel1_PreviewClick(object sender, PreviewMouseEventArgs e) { MessageBox.Show(e.Brick.Text); } private void xrLabel2_PreviewDoubleClick(object sender, PreviewMouseEventArgs e) { MessageBox.Show(e.Brick.Text); }
Run the application and click a label to view the result.
-
Use the DocumentPreviewControl.DocumentPreviewMouseClick and/or DocumentPreviewControl.DocumentPreviewMouseDoubleClick events as shown in the code snippet below.
using DevExpress.XtraPrinting; using DevExpress.Xpf.Printing; private void documentPreview_DocumentPreviewMouseClick_1(DependencyObject d, DocumentPreviewMouseEventArgs e) { LabelBrick brick = e.Brick as LabelBrick; if (brick != null) MessageBox.Show(brick.Text); }
-
Handle the client-side ASPxClientWebDocumentViewer.PreviewClick event as demonstrated below.
<script type="text/javascript" id="script"> function previewClick(s, e) { e.Brick && alert(e.Brick.text()) } </script> <dx:ASPxWebDocumentViewer ID="ASPxWebDocumentViewer1" runat="server" ReportSourceId="WebWebDocumentViewer.XtraReport1"> <ClientSideEvents PreviewClick="previewClick"/> </dx:ASPxWebDocumentViewer>