Share print report in vb.net,

ngoanphuong.tam

New member
#vb.net, #Print, #Report, #development ### Cách in báo cáo trong vb.net

Hướng dẫn này sẽ chỉ cho bạn cách in báo cáo trong vb.net.Chúng tôi sẽ sử dụng [System.Drawing.printing] (System.Drawing.Printing Namespace) Không gian tên để tạo tài liệu in và in nó vào máy in.

#### 1. Tạo một dự án mới

Đầu tiên, tạo một dự án Windows Forms mới trong Visual Studio.

#### 2. Thêm tham chiếu đến System.Drawing.printing không gian tên

Tiếp theo, thêm một tham chiếu đến System.Drawing.printing không gian tên.Bạn có thể làm điều này bằng cách nhấp chuột phải vào dự án của mình trong trình thám hiểm giải pháp và chọn ** Thêm tham chiếu **.Trong hộp thoại ** Trình quản lý tham chiếu **, chọn tab **. Net Framework ** và sau đó cuộn xuống cho đến khi bạn tìm thấy ** system.drawing.printing ** không gian tên.Nhấp vào ** Thêm ** để thêm không gian tên vào dự án của bạn.

#### 3. Tạo một tài liệu in

Để tạo một tài liệu in, bạn cần tạo một thể hiện của [System.Drawing.PrintDocument] (https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument).Bạn có thể làm điều này bằng cách sử dụng mã sau:

`` `VBNet
Dim printDocument dưới dạng system.Drawing.printDocument ()
`` `

#### 4. Thêm trình xử lý sự kiện trang in

Để in báo cáo, bạn cần thêm một trình xử lý sự kiện trang in vào tài liệu in.Bạn có thể làm điều này bằng cách sử dụng mã sau:

`` `VBNet
Private Sub PrintDocument_PrintPage (Người gửi dưới dạng Đối tượng, E AS System.Drawing.Print

'Vẽ báo cáo vào trang in.
e.graphics.

Kết thúc phụ
`` `

#### 5. In báo cáo

Để in báo cáo, bạn cần gọi phương thức ** in ** của tài liệu in.Bạn có thể làm điều này bằng cách sử dụng mã sau:

`` `VBNet
printdocument.print ()
`` `

#### 6. Chạy chương trình

Bây giờ bạn đã tạo tài liệu in và thêm trình xử lý sự kiện trang in, bạn có thể chạy chương trình.Khi bạn làm, báo cáo sẽ được in ra máy in.

### Dưới đây là 5 hashtag mà bạn có thể sử dụng cho bài viết này:

* #vb.net
* #in
* #báo cáo
* #phát triển
* #Programming
=======================================
#vb.net, #Print, #Report, #development ### How to Print a Report in VB.NET

This tutorial will show you how to print a report in VB.NET. We'll use the [System.Drawing.Printing](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing) namespace to create a print document and print it to the printer.

#### 1. Create a new project

First, create a new Windows Forms project in Visual Studio.

#### 2. Add a reference to the System.Drawing.Printing namespace

Next, add a reference to the System.Drawing.Printing namespace. You can do this by right-clicking on your project in the Solution Explorer and selecting **Add Reference**. In the **Reference Manager** dialog box, select the **.NET Framework** tab and then scroll down until you find the **System.Drawing.Printing** namespace. Click **Add** to add the namespace to your project.

#### 3. Create a print document

To create a print document, you need to create an instance of the [System.Drawing.PrintDocument](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument) class. You can do this by using the following code:

```vbnet
Dim printDocument As New System.Drawing.PrintDocument()
```

#### 4. Add a print page event handler

To print the report, you need to add a print page event handler to the print document. You can do this by using the following code:

```vbnet
Private Sub printDocument_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument.PrintPage

' Draw the report to the print page.
e.Graphics.DrawRectangle(Pens.Black, 0, 0, e.PageWidth, e.PageHeight)

End Sub
```

#### 5. Print the report

To print the report, you need to call the **Print** method of the print document. You can do this by using the following code:

```vbnet
printDocument.Print()
```

#### 6. Run the program

Now that you've created the print document and added the print page event handler, you can run the program. When you do, the report will be printed to the printer.

### Here are 5 hashtags that you can use for this article:

* #vb.net
* #Print
* #Report
* #development
* #Programming
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top