GDI画图问题
在一个有背景的FORM中画两条跟随鼠标的十字线要不断的刷新才可以。这样很大的占用了CPU。能不能象在没有背景的FORM中画十字线(即画之前不用刷新)。
------解决方案--------------------看下你的代码
建议用双缓冲技术
------解决方案--------------------使用异或绘图或双缓冲~~
------解决方案--------------------用graphicpath,只需重画十字架的path,不用全部重绘
------解决方案--------------------用两个PIC,然后一个宽度设置为1,一个高度设置为1,跟着你鼠标移动不就OK啦
------解决方案--------------------Public Class Form2
Dim OldPoint As Point
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.UserPaint, True)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
Dim p1, p2, p3, p4 As Point
If OldPoint <> Nothing Then
p1 = PointToScreen(New Point(OldPoint.X, 0))
p2 = PointToScreen(New Point(OldPoint.X, Me.ClientSize.Height))
p3 = PointToScreen(New Point(0, OldPoint.Y))
p4 = PointToScreen(New Point(Me.ClientSize.Width, OldPoint.Y))
ControlPaint.DrawReversibleLine(p1, p2, Color.Cyan)
ControlPaint.DrawReversibleLine(p3, p4, Color.Cyan)
End If
p1 = PointToScreen(New Point(e.X, 0))
p2 = PointToScreen(New Point(e.X, Me.ClientSize.Height))
p3 = PointToScreen(New Point(0, e.Y))
p4 = PointToScreen(New Point(Me.ClientSize.Width, e.Y))
ControlPaint.DrawReversibleLine(p1, p2, Color.Cyan)
ControlPaint.DrawReversibleLine(p3, p4, Color.Cyan)
OldPoint = New Point(e.X, e.Y)
End Sub
End Class
------解决方案--------------------直接把鼠标的光标设为十字架行不行?你的十字架有多大啊。