Skapar först en startrutin för utskrift .....
Notera att jag använder millimeter som GraphicsUnit för att enklare ha kontroll på layouten ...
Imports System.Drawing
Imports System.Drawing.Printing
Friend myPen As Pen = New Pen(Color.Black, 0.1)
Public Sub print_start(ByVal myPrinter As String)
'// dokumentinstans
prDoc = New PrintDocument
prDoc.PrinterSettings.PrinterName = myPrinter
AddHandler prDoc.PrintPage, AddressOf print_page
prDoc.Print()
End Sub
Sedan koden som Handlern hänvisar till ..
Private Sub print_page(ByVal sender As Object, ByVal ev As
PrintPageEventArgs)
ev.Graphics.PageUnit = GraphicsUnit.Millimeter
ev.PageSettings.Margins.Left = 0
ev.PageSettings.Margins.Top = 0
DrawRoundedRectangle(ev.Graphics, 0, 0, 100, 72, 3)
ev.HasMorePages = False
End Sub
Och slutligen den kod som skapar rektangeln i DrawRoundedRectangle ....
Public Sub DrawRoundedRectangle(ByVal objGraphics As Graphics,
ByVal m_sngxAxis As Single, ByVal m_sngyAxis As Single, ByVal
m_sngWidth As Single, ByVal m_sngHeight As Single, ByVal
m_diameter As Single)
'Dim g As Graphics
Dim BaseRect As New RectangleF(m_sngxAxis, m_sngyAxis,
m_sngWidth, m_sngHeight)
Dim ArcRect As New RectangleF(BaseRect.Location, New SizeF
(m_diameter, m_diameter))
'top left Arc
objGraphics.DrawArc(myPen, ArcRect, 180, 90)
objGraphics.DrawLine(myPen, m_angxAxis + m_diameter / 2,
m_angyAxis, m_angxAxis + m_sngWidth - m_diameter / 2, m_sngyAxis)
' top right arc
ArcRect.X = BaseRect.Right - m_diameter
objGraphics.DrawArc(myPen, ArcRect, 270, 90)
objGraphics.DrawLine(myPen, m_sngxAxis + m_sngWidth,
m_sngyAxis + m_diameter / 2, m_sngxAxis + m_sngWidth, m_sngyAxis
+ m_sngHeight - m_diameter / 2)
' bottom right arc
ArcRect.Y = BaseRect.Bottom - m_diameter
objGraphics.DrawArc(myPen, ArcRect, 0, 90)
objGraphics.DrawLine(myPen, m_sngxAxis + m_diameter / 2,
m_sngyAxis + m_sngHeight, m_sngxAxis + m_sngWidth -
m_diameter / 2, m_sngyAxis + m_sngHeight)
' bottom left arc
ArcRect.X = BaseRect.Left
objGraphics.DrawArc(myPen, ArcRect, 90, 90)
objGraphics.DrawLine(myPen, m_sngxAxis, m_sngyAxis +
m_diameter / 2, m_sngxAxis, m_sngyAxis + m_sngHeight -
m_diameter / 2)
End Sub