Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: Passing parameter from one page to another Pin
Richard MacCutchan29-Jun-21 5:44
mveRichard MacCutchan29-Jun-21 5:44 
QuestionCreate the same but in windows form C# Pin
Luis M. Rojas25-Jun-21 6:16
Luis M. Rojas25-Jun-21 6:16 
AnswerRe: Create the same but in windows form C# Pin
OriginalGriff25-Jun-21 6:23
mveOriginalGriff25-Jun-21 6:23 
QuestionDifficulty adding code to reject non numeric user inputs Pin
Member 1524886723-Jun-21 5:58
Member 1524886723-Jun-21 5:58 
AnswerRe: Difficulty adding code to reject non numeric user inputs Pin
OriginalGriff23-Jun-21 6:08
mveOriginalGriff23-Jun-21 6:08 
GeneralRe: Difficulty adding code to reject non numeric user inputs Pin
Member 1524886723-Jun-21 7:15
Member 1524886723-Jun-21 7:15 
GeneralRe: Difficulty adding code to reject non numeric user inputs Pin
OriginalGriff23-Jun-21 7:32
mveOriginalGriff23-Jun-21 7:32 
GeneralLimitless printing Pin
Member 1419221622-Jun-21 1:21
Member 1419221622-Jun-21 1:21 
Hello,
I have a problem with my application at the time of printing. When I print with the print button of the report viewer in the viewer my printing works fine. And when I run printing without previewing the report limit is limited to where the rectangle is limited. I specify well I use a thermal printer in roll paper

Here is my code


C#
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.IO;
 using System.Windows.Forms;
using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;

namespace POS_System_Inventory
{
     public static class LocalReportExtensions
    {
        public static void PrintToPrinter(this LocalReport report)
        {
            PageSettings pageSettings = new PageSettings();
            pageSettings.PaperSize = report.GetDefaultPageSettings().PaperSize;
            pageSettings.Landscape = report.GetDefaultPageSettings().IsLandscape;
            pageSettings.Margins = report.GetDefaultPageSettings().Margins;
            Print(report, pageSettings);
        }
         

        public static void Print(this LocalReport report, PageSettings pageSettings)
        {
            string deviceInfo =
                @"<DeviceInfo>
                    <OutputFormat>EMF</OutputFormat>
                    <PageWidth>{pageSettings.PaperSize.Width * 100}in</PageWidth>
                    <PageHeight>{pageSettings.PaperSize.Height * 100}in</PageHeight>
                    <MarginTop>{pageSettings.Margins.Top * 100}in</MarginTop>
                    <MarginLeft>{pageSettings.Margins.Left * 100}in</MarginLeft>
                    <MarginRight>{pageSettings.Margins.Right * 100}in</MarginRight>
                    <MarginBottom>{pageSettings.Margins.Bottom * 100}in</MarginBottom>
                </DeviceInfo>";
            Warning[] warnings;
            var streams = new List<Stream>();
            var pageIndex = 0;
            report.Render("Image", deviceInfo,
                (name, fileNameExtension, encoding, mimeType, willSeek) =>
                {
                    MemoryStream stream = new MemoryStream();
                    streams.Add(stream);
                    return stream;
                }, out warnings);
            foreach (Stream stream in streams)
                stream.Position = 0;
            if (streams == null || streams.Count == 0)
                throw new Exception("Aucun flux à imprimer.");
            using (PrintDocument printDocument = new PrintDocument())
            {
                printDocument.DefaultPageSettings = pageSettings;
                if (!printDocument.PrinterSettings.IsValid)
                    throw new Exception("Impossible de trouver l'imprimante par défaut.");
                else
                {
                    printDocument.PrintPage += (sender, e) =>
                    {
                        Metafile pageImage = new Metafile(streams[pageIndex]);
                        Rectangle adjustedRect = new Rectangle(e.PageBounds.Left - (int)e.PageSettings.HardMarginX, e.PageBounds.Top - (int)e.PageSettings.HardMarginY, e.PageBounds.Width, e.PageBounds.Height);
                        e.Graphics.FillRectangle(Brushes.White, adjustedRect);
                        e.Graphics.DrawImage(pageImage, adjustedRect);
                        pageIndex++;
                        e.HasMorePages = (pageIndex < streams.Count);
                        e.Graphics.DrawRectangle(Pens.Red, adjustedRect);
                    };
                    printDocument.EndPrint += (Sender, e) =>
                    {
                        if (streams != null)
                        {
                            foreach (Stream stream in streams)
                                stream.Close();
                            streams = null;
                        }
                    };
                    printDocument.Print();
                }
            }
        }
    }
}


modified 22-Jun-21 8:24am.

GeneralRe: Limitless printing Pin
OriginalGriff22-Jun-21 2:26
mveOriginalGriff22-Jun-21 2:26 
GeneralRe: Limitless printing Pin
jsc4222-Jun-21 3:04
professionaljsc4222-Jun-21 3:04 
GeneralRe: Limitless printing Pin
Gerry Schmitz22-Jun-21 6:57
mveGerry Schmitz22-Jun-21 6:57 
QuestionC# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
arnold_w21-Jun-21 21:23
arnold_w21-Jun-21 21:23 
AnswerRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
Gerry Schmitz22-Jun-21 6:43
mveGerry Schmitz22-Jun-21 6:43 
AnswerRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
BillWoodruff22-Jun-21 19:02
professionalBillWoodruff22-Jun-21 19:02 
GeneralRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
Gerry Schmitz23-Jun-21 7:26
mveGerry Schmitz23-Jun-21 7:26 
GeneralRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
BillWoodruff23-Jun-21 23:27
professionalBillWoodruff23-Jun-21 23:27 
GeneralRe: C# graph/diagram showing executing tasks vs time, that scales well with large data sets? Pin
Gerry Schmitz24-Jun-21 6:27
mveGerry Schmitz24-Jun-21 6:27 
QuestionLinking forms Pin
Member 1524886721-Jun-21 12:15
Member 1524886721-Jun-21 12:15 
AnswerRe: Linking forms Pin
Richard Andrew x6421-Jun-21 13:22
professionalRichard Andrew x6421-Jun-21 13:22 
GeneralRe: Linking forms Pin
Member 1524886721-Jun-21 13:31
Member 1524886721-Jun-21 13:31 
GeneralRe: Linking forms Pin
Richard Andrew x6421-Jun-21 13:43
professionalRichard Andrew x6421-Jun-21 13:43 
GeneralRe: Linking forms Pin
Member 1524886721-Jun-21 15:23
Member 1524886721-Jun-21 15:23 
AnswerRe: Linking forms Pin
Gerry Schmitz22-Jun-21 6:32
mveGerry Schmitz22-Jun-21 6:32 
GeneralRe: Linking forms Pin
Member 1524886723-Jun-21 5:14
Member 1524886723-Jun-21 5:14 
QuestionNeed help with straight line depreciation coding Pin
Member 1524886721-Jun-21 8:38
Member 1524886721-Jun-21 8:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.