|
Private Sub cmdArc_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdArc.Click
Dim rect As New Rectangle(50, 50, 200, 100)
‘Cung tròn được vẽ trong
đây
gNoiVe.Clear(Me.BackColor)
‘Xóa trước khi vẽ
gNoiVe.DrawArc(New Pen(Color.Blue), rect, 12, 84)
End Sub
Private Sub cmdBezier_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdBezier.Click
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawBezier(New Pen(Color.Green, 2), 20.0F,
30.0F, 100.0F, _
200.0F, 40.0F, 400.0F, 100.0F, 200.0F)
End Sub
Private Sub cmdBeziers_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdBeziers.Click
Dim p1 As New PointF(40.0F, 50.0F)
' Các điểm trên đường
cong
Dim p2 As New PointF(60.0F, 70.0F)
Dim p3 As New PointF(80.0F, 34.0F)
Dim p4 As New PointF(120.0F, 180.0F)
Dim p5 As New PointF(200.0F, 150.0F)
Dim p6 As New PointF(350.0F, 250.0F)
Dim p7 As New PointF(200.0F, 200.0F)
Dim ptsArray As PointF() = {p1, p2, p3, p4, p5, p6,
p7}
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawBeziers(New Pen(Color.Red, 2), ptsArray)
End Sub
Private Sub cmdCurve_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdCurve.Click
Dim bluePen As New Pen(Color.Blue, 1)
Dim pt1 As New PointF(40.0F, 50.0F)
' Dãy các điểm
Dim pt2 As New PointF(50.0F, 75.0F)
Dim pt3 As New PointF(100.0F, 115.0F)
Dim pt4 As New PointF(200.0F, 180.0F)
Dim pt5 As New PointF(200.0F, 90.0F)
Dim ptsArray As PointF() = {pt1, pt2, pt3, pt4, pt5}
Dim offset As Integer = 1
‘Bước nhảy (số điểm) để
tạo 1 đoạn trên đường cong
Dim segments As Integer = 3
‘Số đoạn trên đường cong
(<= số điểm trừ 2)
Dim tension As Single = 0.5F
‘Độ căng của đường cong,
càng nhỏ càng thẳng
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawCurve(bluePen, ptsArray, offset,
segments, tension)
bluePen.Dispose()
‘Giải phóng bút vẽ
End Sub
Private Sub cmdClosedCurve_Click(ByVal sender
As System.Object, _
ByVal e As System.EventArgs) Handles
cmdClosedCurve.Click
Dim pts() As Point = {New Point(10, 50), _
New Point(200, 30), New Point(120, 200), _
New Point(230, 150), New Point(150, 50), _
New Point(250, 200), New Point(100, 250)}
gNoiVe.SmoothingMode =
Drawing2D.SmoothingMode.HighQuality
gNoiVe.Clear(Me.BackColor)
For tension As Single = 0 To 1 Step 0.25
Dim curve_pen As New Pen(Color.Black, tension * 4
+ 1)
gNoiVe.DrawClosedCurve(curve_pen, pts, tension, _
Drawing2D.FillMode.Alternate)
Next tension
For i As Integer = 0 To pts.Length - 1
gNoiVe.FillRectangle(Brushes.White,pts(i).X -
2,pts(i).Y - 2, 5,5)
gNoiVe.DrawRectangle(Pens.Black, pts(i).X - 2,
pts(i).Y - 2, 5, 5)
Next i
End Sub
Private Sub cmdEllipse_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdEllipse.Click
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawEllipse(New Pen(Color.Blue), 10, 10, 250,
150) ‘Ê-líp
gNoiVe.DrawEllipse(New Pen(Color.Blue), 10, 10, 150,
150) ‘Tròn
End Sub
Private Sub cmdIcon_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdIcon.Click
Dim appPath As String =
My.Computer.FileSystem.CurrentDirectory
‘ Chép 2 file
icon mà bạn có vào thư mục bin\debug của ứng dụng
Dim icon1 As New Icon(appPath & "\Apple.ico")
Dim icon2 As New Icon(appPath & "\Aero-Soft.ico")
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawIcon(icon1, 20, 50)
‘Vẽ tại một vị trí,
không tính chuyện co dãn
Dim rect As New Rectangle(100, 200, 20, 20)
gNoiVe.DrawIcon(icon2, rect)
‘Co dãn cho khớp với
hình chữ nhật cho trước
Dim rectUnstretched As New Rectangle(50, 200, 20,
20)
gNoiVe.DrawIconUnstretched(icon2, rectUnstretched)
‘Không co dãn
End Sub
Private Sub cmdImage_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdImage.Click
Dim appPath As String =
My.Computer.FileSystem.CurrentDirectory
Dim imageFile As Image = Image.FromFile(appPath & "\LogoBV.jpg")
Dim rect As New Rectangle(50, 50, 60, 60)
Dim rectUnscaled As New Rectangle(150, 50, 50, 50)
Dim rectUnscaledAndClipped As New Rectangle(10, 150,
100, 80)
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawImage(imageFile, rect)
‘Co dãn cho khớp với
hình chữ nhật cho trước
gNoiVe.DrawImageUnscaled(imageFile, rectUnscaled)
‘Không co dãn
‘Không co dãn
và cắt bớt cho vừa khung chữ nhật cho trước
gNoiVe.DrawImageUnscaledAndClipped(imageFile,
rectUnscaledAndClipped)
End Sub
Private Sub cmdLine_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdLine.Click
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawLine(New Pen(Color.Black, 1), 50, 50,
100, 100)
End Sub
Private Sub cmdLines_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdLines.Click
Dim points(3) As Point
points(0) = New Point(120, 60)
points(1) = New Point(180, 60)
points(2) = New Point(240, 120)
points(3) = New Point(60, 120)
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawLines(New Pen(Color.Blue), points)
End Sub
Private Sub cmdPath_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdPath.Click
Dim path As GraphicsPath = New GraphicsPath
‘Vẽ 1 loạt 4
hình theo thứ tự: đường kẻ, ê-líp, đường kẻ, hình chữ
nhật
path.AddLine(20, 20, 103, 80)
‘Thêm 1 đường kẻ vào
path
path.AddEllipse(100, 50, 100, 100)
‘Thêm 1 hình ê-líp vào
path
path.AddLine(195, 80, 300, 80)
Dim rect As Rectangle = New Rectangle(50, 150, 300,
50)
path.AddRectangle(rect)
‘Thêm 1 hình chữ nhật
vào path
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawPath(New Pen(Color.Green, 1), path)
End Sub
Private Sub cmdPie_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdPie.Click
Dim startAngle As Single = 180
‘Bắt đầu từ vị trí góc
180 độ
Dim sweepAngle As Single = 60
‘Quét 1 góc 60 độ
Dim bluePen As Pen = New Pen(Color.Blue, 1)
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawPie(bluePen, 20, 20, 100, 100,
startAngle, sweepAngle)
End Sub
Private Sub cmdPolygon_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdPolygon.Click
Dim points(3) As Point
points(0) = New Point(120, 60)
‘Đỉnh phía trên bên trái
hình thang
points(1) = New Point(180, 60)
‘Đỉnh phía trên bên phải
hình thang
points(2) = New Point(240, 120)
‘Đỉnh phía dưới bên phải
hình thang
points(3) = New Point(60, 120)
‘Đỉnh phía dưới bên trái
hình thang
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawPolygon(New Pen(Color.Blue), points)
End Sub
Private Sub cmdRectangle_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdRectangle.Click
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawRectangle(New Pen(Color.Blue, 1), 50, 50,
150, 150)
gNoiVe.DrawRectangle(New Pen(Color.Red, 1), 10, 10,
250, 150)
End Sub
Private Sub cmdRectangles_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdRectangles.Click
Dim rects(3) As Rectangle
‘Bản dãy 4 hình chữ nhật
rects(0) = New Rectangle(10, 10, 250, 150)
rects(1) = New Rectangle(20, 20, 250, 150)
rects(2) = New Rectangle(30, 30, 250, 150)
rects(3) = New Rectangle(40, 40, 250, 150)
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawRectangles(New Pen(Color.Blue), rects)
End Sub
Private Sub cmdString_Click(ByVal sender As
System.Object, _
ByVal e As System.EventArgs) Handles
cmdString.Click
Dim drawFont As New Font("Verdana", 14)
‘Chọn 1 kiểu phông chữ
Dim drawFormat As New StringFormat
‘ Đổi hướng vẽ chuỗi
thành chiều đứng
drawFormat.FormatFlags =
StringFormatFlags.DirectionVertical
gNoiVe.Clear(Me.BackColor)
gNoiVe.DrawString("Vẽ chuỗi", New Font("Times New
Roman", 14),_
New SolidBrush(Color.Green), 20, 20)
gNoiVe.DrawString("Chuỗi in nằm ngang!", New
Font("Arial", 12),_
New SolidBrush(Color.Red), 120, 140)
gNoiVe.DrawString("Chuỗi in thẳng đứng!", drawFont,
_
New SolidBrush(Color.Blue), 100.0F, 50.0F,
drawFormat)
End Sub |