Winform printing form

Source: Internet
Author: User

This article from: http://www.cnblogs.com/liushaoyu/archive/2011/03/04/JadeLiu.html

 

Winfrom often involves the printing function. The most printed on the internet is about the list form such as gridview.

Google can search for a lot of code that can be used.

 

This document records the printing of winfrom forms that you encounter.

The effect is as follows:

 

We started to open a form such as vs design: there is a small skill in designing a form, which can improve the speed and accuracy of the layout.

1. Capture the image in the Form format to be printed. For example, if you need to print the above form, the customer will generally provide me with the corresponding Excel, and I use a tool to capture the image and save it locally.

2. Click set from attribute in vs: background image to set the image we just captured. Note that both QQ and windows have shadow, which affects the display effect. Other tools are recommended. I use picpick.

 

If you follow the above steps, the following results are generally displayed.

In this way, you can quickly deploy what the customer wants. Isn't it very fast? Drag the Textbox Control in the blank area and start the end of the interface design.

3. Start printing.

In general, I started to print it like this. I first drew a table and then installed the above layout in the table to draw different labels.

According to the above ideas, I suddenly found that the workload was not small, and this table was also merged.

Is there a simpler method.

The answer is why I wrote this blog.

 1   PrivateVoidPrintdocumentemediprintpage (ObjectSender, system. Drawing. Printing. printpageeventargs E)

2 {
3 Graphics g = E. graphics; // Create a canvas first
4 Int X =   80 ;
5 Int Y =   60 ;
6 G. drawimage ( This . Backgroundimage, 50 , 50 );
7 Foreach (Control item In   This . Controls)
8 {
9 If (Item Is Textbox)
10 {
11 Control TX = (Item As Control );
12 G. drawstring (TX. Text, TX. Font, brushes. Black, TX. Left + X, TX. Top + Y );
13 }
14
15 }
16 }

ShortCodeSuddenly liberated me and suddenly felt that the world is beautiful.

Okay. Start running ourProgramRight.

Click print to see if the effect is what we want?

 

Haha... It looks like what we need... Let's take a look at the content.

 

Print it again. A miracle appears.

 

Yes, so that our task is completed...

The code is relatively simple. The main idea is to solve this problem. According to the general principle, some computing time and debugging time may be required.

Of course, I think more people may think of better and simpler than me. If you are, please share your message with me. Thank you.

Bytes --------------------------------------------------------------------------------------------------------------------

I wonder if it is necessary to explain the code? The screenshot description is as follows. It is a great pleasure to help you.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.