读书人

直线的平移有关问题,

发布时间: 2012-01-19 20:57:58 作者: rapoo

直线的平移问题,急急急,在线等.
有关直线的平移,我写了以下代码:
Public Class Form1
Public Sub TranslateClipInt(ByVal e As PaintEventArgs)
' Create graphics path.
Dim myPath As New GraphicsPath
myPath.AddLine(30, 30, 600, 600)
e.Graphics.SetClip(myPath) '把线段设置为剪切区
Dim dx As Integer = 0 '平移量
Dim dy As Integer = 0
e.Graphics.TranslateClip(dx, dy)
' Draw the path to the screen.
Dim myPen As New Pen(Color.Black, 2)
e.Graphics.DrawPath(myPen, myPath)
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
TranslateClipInt(e)
End Sub
End Class
可是总得不到预期效果,请问高手,我哪里错了,应该怎样实现?

[解决办法]
看看这个,就实现了平移,结果只能在Rectangle(50, 50, 100, 100)里绘制图形了

Public Sub TranslateClipInt(ByVal e As PaintEventArgs)
Dim clipRect As New Rectangle(0, 0, 100, 100)
e.Graphics.SetClip(clipRect)

Dim dx As Integer = 50
Dim dy As Integer = 50

e.Graphics.TranslateClip(dx, dy)

e.Graphics.FillRectangle(New SolidBrush(Color.Black), 0, 0, 500, 1000)
End Sub

读书人网 >VB Dotnet

热点推荐