📄 drawer.vb
字号:
Public Class Drawer
Inherits Visitor
Private m_Style, m_Width, m_Color, aDStyle, aWidth As Integer
Private aPen, oldP, aColor As Long
Public Sub preDraw(ByVal hdc As IntPtr)
'设置画笔参数
Win32API.SetROP2(hdc, 13)
m_Style = 0
m_Width = 3
m_Color = RGB(255, 0, 0)
'创建画笔
aPen = Win32API.CreatePen(m_Style, m_Width, m_Color)
'把画笔选入绘图环境,并返回原来的画笔
oldP = Win32API.SelectObject(hdc, aPen)
End Sub
Public Sub postDraw(ByVal g As Graphics, ByVal hdc As IntPtr)
'把原来的画笔选入绘图环境
Win32API.SelectObject(hdc, oldP)
'删除新创建的画笔
Win32API.DeleteObject(aPen)
'释放绘图环境句柄
g.ReleaseHdc(hdc)
End Sub
Public Overloads Overrides Sub toDraw(ByVal g As Graphics, ByVal line As CLine)
Dim hdc As IntPtr = g.GetHdc
preDraw(hdc)
'把画笔移动到直线段的起点处
Win32API.MoveToEx(hdc, 50, 50, Nothing)
'绘直线段到终点
Win32API.LineTo(hdc, 200, 200)
postDraw(g, hdc)
End Sub
Public Overloads Overrides Sub toDraw(ByVal g As Graphics, ByVal circle As CCircle)
Dim hdc As IntPtr = g.GetHdc
preDraw(hdc)
'把空刷子选入绘图环境
Win32API.SelectObject(hdc, Win32API.GetStockObject(5))
'绘圆
Win32API.Ellipse(hdc, 100, 80, 300, 400)
postDraw(g, hdc)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -