感谢CSDN!图像重画,已经解决!贴上源码!
郁闷了一个下午,终于解决了多次重画图形问题!
感谢:dylike、bw555、yanlongwuhui、keenweiwei
更感谢CSDN
下面是我用bitmap解决画图闪烁,用数组解决重画的源码(只画直线):
Public Class Form1 Dim Bmp1 As Bitmap Dim IsDown As Boolean = False Dim myPen As New Pen(Color.GreenYellow, 2) Dim arrayLine(,) As Point Dim pLine1, pLine2 As Point Dim countLine, countRect, countEillpse As Integer Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown IsDown = True pLine1.X = e.X pLine1.Y = e.Y End Sub Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove If IsDown Then Dim gbmp As Graphics = Graphics.FromImage(Bmp1) pLine2.X = e.X pLine2.Y = e.Y gbmp.Clear(Color.Gainsboro) Dim i As Integer If countLine <> 0 Then For i = 0 To countLine gbmp.DrawLine(myPen, arrayLine(1, i).X, arrayLine(1, i).Y, arrayLine(2, i).X, arrayLine(2, i).Y) Next End If gbmp.DrawLine(myPen, pLine1.X, pLine1.Y, pLine2.X, pLine2.Y) Me.CreateGraphics.DrawImage(Bmp1, 0, 0) End If End Sub Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp IsDown = False countLine += 1 ReDim Preserve arrayLine(2, countLine) arrayLine(1, countLine) = pLine1 arrayLine(2, countLine) = pLine2 End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Bmp1 = New Bitmap(Me.Size.Width, Me.Size.Height) countLine = 0 End SubEnd Class