How to create print rule with custome design page in c#
Loading
How to create print rule with custome design page in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajkiran SwainPosted Jun 19, 2023, 10:57 AM
To create a print rule with a custom-designed page in C#, you can follow these general steps:
Design the print page: Create a custom-designed page using a library like Windows Forms or WPF. You can add various controls, such as labels, images, and text boxes, to represent the content you want to print.
Set up a PrintDocument object: Instantiate a PrintDocument object, which represents the document to be printed. Set the properties of the PrintDocument object, such as the document name and the event handlers for printing-related events.
Handle the PrintPage event: Implement the event handler for the PrintPage event of the PrintDocument object. This event is raised for each page to be printed. In the event handler, you can use the Graphics object provided by the event arguments to draw the content onto the print page based on your custom design.
Handle the BeginPrint and EndPrint events (optional): If necessary, you can implement event handlers for the BeginPrint and EndPrint events to perform any initialization or cleanup tasks before and after the printing process.
Call the Print method: After setting up the print document and its event handlers, you can call the Print method of the PrintDocument object to start the printing process. This will trigger the PrintPage event for each page to be printed.
Here's a simplified example using Windows Forms:
Deepak RawatPosted Jun 19, 2023, 10:49 AM
PrintButton_Clickevent handler is responsible for initiating the print process. It creates an instance of thePrintDocumentclass and subscribes to itsPrintPageevent. ThePrintDocument_PrintPageevent handler is responsible for defining the content and layout of the print document using theGraphicsobject.You can customize the print document as per your requirements, adding your own design, layout, and content using various
Graphicsmethods.Mohamed Azarudeen ZPosted Jun 19, 2023, 9:41 AM
Hi arvnd
Create a new Windows Forms Application project in Visual Studio.
Add a button to your form that will trigger the printing action. You can do this by dragging and dropping a Button control from the Toolbox onto your form.
Double-click on the button to generate the click event handler and add the following code inside the event handler:
Implement the
PrintDocument_PrintPageevent handler to define the custom printing logic. This event will be triggered for each page of the document to be printed. Inside this event handler, you can use theGraphicsobject to draw your custom content on the page. Here's an example that draws a simple message on the page:Run the application, and when you click the button, the print dialog will appear, allowing you to select the printer and adjust print settings. After confirming the settings, the
PrintDocument_PrintPageevent will be triggered for each page, and the custom content will be drawn on each page.