我正在嘗試使用 Vb.net 重新創建標簽
我有這個要重新創建的標簽:

到現在為止我所做的:
我試圖改變線條但無法做到那樣,我什至不知道如何排列或移動或添加新的列或行。
我在網上找到的代碼:
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim ht As Single = 7 ' Table Height
Dim wt As Single = 5 ' Table Width
Dim r As Integer = 15, c As Integer = 2 ' Rows and Cols in Table
Dim Cht As Single ' Cell Height
Dim lst As Single ' last line drawn
Dim i As Integer
Dim p As Pen
Cht = CSng(Math.Round(ht / r, 2)) * c
lst = 0.5F Cht ' 0.5->default margin
p = New Pen(Color.Black, 0.025F)
e.Graphics.PageUnit = GraphicsUnit.Inch
e.Graphics.DrawRectangle(p, 0.5F, 0.5F, wt, ht) ' border of the table
p.Color = Color.Blue
For i = 0 To CInt(r / c) - 1 ' lines in the table
e.Graphics.DrawLine(p, 0.5F, lst, 0.5F wt, lst)
lst = Cht
Next
End Sub
我迷路了,我不知道如何創建類似的標簽。最好的方法是什么?
uj5u.com熱心網友回復:
以下內容將幫助您開始創建 OP 中所示的標簽。
我將使用一個名為 .NET 的表單的 Windows 表單應用程式 (.NET Framework) 專案Form1。
添加以下 Imports 陳述句:
Imports System.Drawing.Drawing2DImports System.Drawing.Printing
為了繪制圓角矩形,我們將
Add a PrintDocument to Form1 (name: PrintDocument1)
Subscribe to Paint event
- In Properties Window, select PrintDocument1 from the drop-down
- Click

- Double-click PrintPage to add the event handler to the form
Add a Button to the Form (name: btnPrint)
Subscribe to Click event
- In Properties Window, select btnPrint from the drop-down
- Click

- Double-click Click to add the event handler to the form
Usage (Panel):
Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint
CreateProductLabel(e.Graphics)
End Sub
Usage (PrintDocument):
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
PrintDocument1.Print()
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
CreateProductLabel(e.Graphics)
End Sub
Here's what the Form looks like:

Resources:
- How to draw a rounded rectangle in c#
- System.Drawing.Namespace
- System.Drawing.Drawing2D Namespace
- System.Drawing.Printing Namespace
- Graphics.MeasureString Method
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/448303.html
