crotate.vb
来自「苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码」· VB 代码 · 共 79 行
VB
79 行
'旋转变换
Public Class CRotate
Implements ICommand
Private m_Step As Integer
Private m_basePos, m_desPos As PointF
'单击鼠标左键时的绘图行为
Public Sub LButtonDown(ByVal g As Graphics, ByVal aPos As PointF) Implements ICommand.LButtonDown
Dim i As Integer
'鼠标单击次数加1
m_Step += 1
Select Case m_Step
Case 1
m_basePos = aPos
m_desPos = aPos
Case 2
'清除最后一条橡皮线
Dim tempLine As New CLine(m_basePos, m_desPos)
tempLine.Draw(g, CGElement.geDrawMode.Drag)
tempLine = Nothing
'如果选择集中的图元个数大于0
If geSels.Count > 0 Then
Dim aAngle As Single
'计算旋转角度
aAngle = GetAngle(m_basePos, m_desPos)
For i = 0 To geSels.Count - 1
'清除图元在当前位置的图形
geSels(i).Draw(g, CGElement.geDrawMode.Delete)
'将所有被选中的图元旋转到目标位置并进行绘制
geSels(i).Rotate(g, m_basePos, aAngle)
geSels(i).Draw(g, CGElement.geDrawMode.Selec)
Next i
End If
m_Step = 0
End Select
End Sub
'移动鼠标时的绘图行为
Public Sub MouseMove(ByVal g As Graphics, ByVal aPos As PointF) Implements ICommand.MouseMove
Select Case m_Step
Case 1
Dim prePos As New PointF()
Dim curPos As New PointF()
prePos = m_desPos
curPos = aPos
'清除上一条橡皮线
Dim tempLine1 As New CLine(m_basePos, prePos)
tempLine1.Draw(g, CGElement.geDrawMode.Drag)
tempLine1 = Nothing
'绘当前位置的橡皮线
Dim tempLine2 As New CLine(m_basePos, curPos)
tempLine2.Draw(g, CGElement.geDrawMode.Drag)
tempLine2 = Nothing
m_desPos = aPos
End Select
End Sub
'单击鼠标右键时的绘图行为
Public Sub RButtonDown(ByVal g As Graphics, ByVal aPos As PointF) Implements ICommand.RButtonDown
If m_Step = 1 Then
'清除上一条橡皮线
Dim tempLine As New CLine(m_basePos, m_desPos)
tempLine.Draw(g, CGElement.geDrawMode.Drag)
tempLine = Nothing
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?