Skip to main content
A newer version of this page is available. .

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:

  1. Start Microsoft Visual Studio 2010, 2012, 2013, 2015 or 2017 and create a new application under any of the supported platforms, or open an existing one.
  2. Add a new blank report to the application.
  3. Drop two XRLabel controls from the DX.18.2: Report Controls Toolbox tab onto the Detail band.

    HowTo_ObtainTextPreview_0

  4. 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.

      HowTo_ObtainTextPreview_1

    • Document Preview for WPF

      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);
      }
      
    • Web Document Viewer

      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>
      
See Also